/*将数组[1,2,3,4]转换为对象数组
[{id: '1', text: '1'},{id: '2', text: '2'},{id: '3', text: '3'},{id: '4', text: '4'}]
*/
function exchangeForm(a) {
var newA = []
for(var i in a) {
newA.push({
id: ''+a[i],
text: ''+a[i]
})
}
return newA;
}
console.log(exchangeForm([1,2,3,4]))
上面是将数组转为对象数组的方法,因为发现搜索数字时不能正常搜索,所以就算是数字也要转化为字符串,测试了一下能够正常搜索
$('#barNo').combobox({
valueField: 'id',//绑定字段ID
textField: 'text',//绑定字段Name
data: exchangeForm([1,2,3,4]),
width: 160,
height: 30,
panelHeight: 'auto',//自适应
multiple: false,
prompt:'输入关键字后自动搜索',
required:true,
onLoadSuccess: function (data) {
console.log(data)
}
});