Php 如何从select2下拉列表中的两个字段进行搜索
我刚刚开始使用select2,当我使用以下两个字段填充选择时,它工作正常:Php 如何从select2下拉列表中的两个字段进行搜索,php,jquery-select2,Php,Jquery Select2,我刚刚开始使用select2,当我使用以下两个字段填充选择时,它工作正常: function formatemp(item) { return item.empnum + " : " + item.empname; } $("#empsDropDown").select2({ data:{ results: <?PHP echo json_encode($employees);?>, text: 'empname'}, placeholder: " &
function formatemp(item) { return item.empnum + " : " + item.empname; }
$("#empsDropDown").select2({
data:{ results: <?PHP echo json_encode($employees);?>, text: 'empname'},
placeholder: " <?PHP echo lang("All");?> ",
minimumInputLength: 2,
allowClear: true,
id: function(obj) {return obj.empnum; },
formatResult: formatemp,
formatSelection: formatemp
});
一点。所以它只搜索名字。如果在搜索框中键入“B”,它将筛选并查找Bloggs等。但是,如果在搜索框中键入“0”,它将不返回任何结果
是否要让它同时搜索两个字段(empname和empnum)
我是select2的新手,所以我希望这是我还没有尝试过的东西
我试过了
text:'empname'+'empnum'
和text:'empname',text:'empnum'
除此之外,我已经在这个网站上搜索了文档,但我似乎只能在其中一个网站上搜索,而不是在两个网站上搜索。我也尝试过定制匹配器,但这似乎也不符合目的。通过暴力找到了解决方案。如果有人有更好的解决方案,我愿意听取
function formatemp(item) { return item.empnum + " : " + item.empname; }
$("#empsDropDown").select2({
data:{ results: <?PHP echo json_encode($employees);?>, text: formatemp},
placeholder: " <?PHP echo lang("All");?> ",
minimumInputLength: 2,
allowClear: true,
id: function(obj) {return obj.empnum; },
formatResult: formatemp,
formatSelection: formatemp
});
函数formatemp(item){return item.empnum+“:“+item.empname;}
$(“#empsDropDown”)。选择2({
数据:{results:,text:formatemp},
占位符:“”,
最小输入长度:2,
allowClear:是的,
id:function(obj){return obj.empnum;},
formatResult:formatemp,
formatSelection:formatemp
});
我刚刚用我用来填充列表的格式化程序函数text:formatemp
替换了text:'empname'
。我从来没想过它会起作用,但它确实起了作用,非常好
function formatemp(item) { return item.empnum + " : " + item.empname; }
$("#empsDropDown").select2({
data:{ results: <?PHP echo json_encode($employees);?>, text: formatemp},
placeholder: " <?PHP echo lang("All");?> ",
minimumInputLength: 2,
allowClear: true,
id: function(obj) {return obj.empnum; },
formatResult: formatemp,
formatSelection: formatemp
});