$('#aaa').selectivity({
allowClear: true,
// multiple:true,
items: ['Amsterdam', 'Antwerp', 'Amsterdam1', 'Antwerp1', 'Antwerp2', 'Amsterdam2', 'Antwerp3'],
placeholder: '请选择'
});这个下拉框只能显示value,不能填key的吗?
修改成统一获取方式,增加显示值的办法:
$("#example-4").on("change", function(e) {
alert("暗码值:" + e.value + " 显示值:" + e.text)
});760行增加text:
change: ['added', 'removed', 'value', 'text'],
4754行改成:
var data = assign({
value: this._value,
text: this._data.text
}, options);
回复
总结上面大佬结论大体写法如下:
$("#aaa").on("change", function(e){
var val = $('#aaa').selectivity('value');
});通过onchange事件触发后获取到的val就是当前选项的值,可以写一个隐藏的input存进去
关于大数据量十万条数据以上:采用异步分页加载
// 初始化 下拉框模糊查询
$('#programList').selectivity({
allowClear: true,
ajax: {
url: '${ctx}/vod_day/programList',
minimumInputLength: 2, // 输入最少2个字符进行搜索
quietMillis: 500,
params: function(term, offset) {
return {
// input 输入的参数
vodName: term,
pageNum: 1 + Math.floor(offset / 100) // 分批加载 每次100条
};
},
fetch: function(url, init, queryOptions) {
return $.ajax(url).then(function(data) {
return {
results: $.map(data.programList, function(item) {
return {
id: item.id,
text: item.text
};
}),
// 总条数 > 当前条数 + 已加载条数 为true 继续发送请求
more: (data.total_count > queryOptions.offset + data.programList.length)
};
});
}
},
placeholder: '搜索节目名称',
templates: {
resultItem: function(item) {
return (
'' +
'' + escape(item.text) + '' +
''
);
}
}
});
回复
<div id="aaa"></div> <input type="hidden" name="name" id="inputa"> </div>
<script>
var data = [{
id: 0,
text: 'enhancement'
}, {
id: 1,
text: 'bug'
}, {
id: 2,
text: 'duplicate'
}, {
id: 3,
text: 'invalid'
}, {
id: 4,
text: 'wontfix'
}];
$('#aaa').selectivity({
allowClear: true,
multiple: true,
data: data,
showSearchInput: true,
placeholder: '请选择',
});
</script>写成这样,可选取,选值了,怎样取ID的值提交?