So I’ve created a giant object, that goes through a database table and collects all the rows with appropriate column names like so (sx is a string that is outputted into javascript):
if (i == 0)
{
sx += "SearchAutocomplete['"+ s.Key + "'] = {};";
}
sx += "SearchAutocomplete['" + s.Key + "'][" + i + "] = '" + s.Value + "';";
(the above is C# code but the error is the javascript part).
My goal is to use this giant object to put it inside autocomplete() function of JQuery UI, based on the column name…
http://jqueryui.com/demos/autocomplete/
htmltable += sx + "$('#mySearchBox').autocomplete({" +
"source: jQuery.makeArray(SearchAutocomplete['" + columnName + "'])" +
"});"
I tried using jQuery.makeArray, but no matter what I try, it doesn’t recognize SearchAutocomplete[‘columnName’] as an array of values.
The autocomplete doesn’t work.
I’m guessing the solution is to somehow loop through and convert the object back into an array maybe. But is there an easier way?
Attempt to fix #1:
if(list_fields.ContainsKey(s.Key)){
if (i == 0)
{
sx += "SearchAutocomplete['"+ s.Key + "'] = [];";
}
sx += "SearchAutocomplete['" + s.Key + "'].push('" + s.Value + "');";
}
Maybe try this change:
That way,
SearchAutocomplete[columnName]is a native array to start.