autocomplete - Jquery UI autcomplete with Json data source -
i using jquery ui autocomple json data source it's not working when used same fixed data works. below code.
$(document).ready(function () { var codes = ""; admin_basicfeeschedule.loadcptcodes().done(function (response) { if (response.status != false) { if (response.cptcodecount > 0) { var cptcodeloadjsondata = json.parse(response.cptcodeload_json); $.each(cptcodeloadjsondata, function (i, item) { codes = codes + "'" + item.shortname + "'"; }); //codes = codes + "]"; alert(codes); } } else { utility.displaymessages(response.message, 3); } }); $.widget("ui.autocomplete", $.ui.autocomplete, { _rendermenu: function (ul, items) { var = this; $.each(items, function (index, item) { that._renderitemdata(ul, item); }); $(ul).wrap("<div></div>"); }, }); $("input#ddlcptcode").autocomplete({ source: [codes],//['tom', 'alex', 'patrick'], }); });
based on jqueryui's api, source option can either array or string points url or function. furthermore, code needs change few things array handled in appropriate fashion:
$(document).ready(function () { var codes = []; // array created admin_basicfeeschedule.loadcptcodes().done(function (response) { //alert("loadcptcodes works") ; if (response.status != false) { //alert("response.status true") ; if (response.cptcodecount > 0) { //alert("cptcodecount > 0") ; var cptcodeloadjsondata = json.parse(response.cptcodeload_json); $.each(cptcodeloadjsondata, function (i, item) { codes.push(item.shortname); //add item array }); //codes = codes + "]"; alert(codes); } } else { utility.displaymessages(response.message, 3); } }); $.widget("ui.autocomplete", $.ui.autocomplete, { _rendermenu: function (ul, items) { var = this; $.each(items, function (index, item) { that._renderitemdata(ul, item); }); $(ul).wrap("<div></div>"); }, }); $("input#ddlcptcode").autocomplete({ source: codes // pass array (without comma) }); });
finally, if changes related array aren't enough make work, check json load part. have added alert calls can uncommented json testing purposes. not familiar details of json load functionality used in sample code, i'm going mention there alternative ways of loading json data such jquery's getjson method.
Comments
Post a Comment