im试图将此array
添加到jQuery SumoSelect librery
var devices= [{
text: "iphone",
value:"iphone"
},
{
text: "android",
value:"android"
},
{
text: "mac",
value:"mac"
}]
请使用以下代码阅读
$("select").SumoSelect({search: true, searchText: 'search'});
for(var i in devices){
$(".type-vehicle").append("<option>"+devices[i].text+"</option>");
}
它向我显示了一个空的选择,但是如果我不使用SumoSelect librery就可以做到这一点,那么它可以很好地工作,我的意思是它向我显示了3种设备的选择输入。
你们知道发生了什么吗?为什么用SumoSelect librery拒绝我的数组?谢谢!
答案 0 :(得分:2)
您需要先填充选择框,然后调用SumoSelect。你差点就吃了!
SELECT
var devices = [{
text: "iphone",
value: "iphone"
},
{
text: "android",
value: "android"
},
{
text: "mac",
value: "mac"
}
]
for(var i in devices){
$("select").append("<option>"+devices[i].text+"</option>");
}
$("select").SumoSelect({search: true, searchText: 'search'});