您最好执行搜索客户端,如果您的数据如此简单,则不需要插件。这是您可以详细说明的 Javascript 工作示例:
var Test = {
Items : [ { "product": "132431",
"productName": "AXE Body Spray 1",
"categoryName": "Hygene"
},
{ "product": "132432",
"productName": "AXE Body Spray 2",
"categoryName": "Hygene"
},
{ "product": "132433",
"productName": "AXE Body Spray 3",
"categoryName": "Hygene"
},
{ "product": "11",
"productName": "Bacon",
"categoryName": "Food"
},
{ "product": "12",
"productName": "Eggs",
"categoryName": "Food"
},
{ "product": "9",
"productName": "Beer",
"categoryName": "Beverages"
}
],
searchProduct: function(search) {
var founds = $.grep(Test.Items, function(value, index) {
return value.productName.substring(0, search.length) == search;
});
Test.printResults(founds);
},
searchCategory: function(search) {
var founds = $.grep(Test.Items, function(value, index) {
return value.categoryName.substring(0, search.lenght) == search;
});
Test.printResults(founds);
},
printResults: function(founds) {
var html = "";
$.each(founds, function(key, item) {
html += "<option>" + item.productName + "</option>\n";
});
alert(html);
}
};
你可以像这样测试它:Test.searchProduct("AXE");
或Test.searchCategory("Food");
. 祝你好运!