I’m trying to use this amazing plugin: http://code.drewwilson.com/entry/autosuggest-jquery-plugin
The problem I’m having is that obviously I need to populate my own data with the following:
kwords.push({"value": "0", "name": item.keyword});
Firebug is reporting that ‘kwords’ is not a function (because it’s not an array), yet I’ve copied and pasted the example code on the plugin page as follows:
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"}
]};
So my entire code looks like (and please note this IS an example):
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"});
(the keyword in the ‘item.keyword’ is taken from an AJAX call).
Can someone explain what I’m doing wrong.
kwordsis an object, thus there should be nopushmethod.What I am assuming you want to do is
kwords.items.push({"value": "0", "name": item.keyword});, which targets the array nameditemsinside thekwordsobject