我正在尝试使用这个神奇的插件:http://code.drewwilson.com/entry/autosuggest-jquery-plugin
我遇到的问题显然是我需要使用以下内容填充自己的数据:
kwords.push({"value": "0", "name": item.keyword});
Firebug报告'kwords'不是函数(因为它不是数组),但我已经在插件页面上复制并粘贴了示例代码,如下所示:
var kwords= {items: [
{value: "21", name: "Mick Jagger"},
{value: "43", name: "Johnny Storm"},
{value: "46", name: "Richard Hatch"},
{value: "54", name: "Kelly Slater"},
{value: "55", name: "Rudy Hamilton"},
{value: "79", name: "Michael Jordan"}
]};
所以我的整个代码看起来像(请注意这是一个例子):
var kwords= {items: [
{value: "21", name: "Mick Jagger"},
{value: "43", name: "Johnny Storm"},
{value: "46", name: "Richard Hatch"},
{value: "54", name: "Kelly Slater"},
{value: "55", name: "Rudy Hamilton"},
{value: "79", name: "Michael Jordan"}
]};
kwords.push({"value": "0", "name": item.keyword});
$("#divSelectedKeywords input").autoSuggest(kwords.items, {selectedItemProp: "name", searchObjProps: "name"});
('item.keyword'中的关键字取自AJAX调用。)
有人可以解释我做错了什么。
答案 0 :(得分:1)
kwords
是一个对象,因此不应该有push
方法。
我假设您要做的是kwords.items.push({"value": "0", "name": item.keyword});
,它定位items
对象中名为kwords
的数组