Undefined Results in jQuery Autocomplete

半腔热情 提交于 2019-12-23 15:09:51

问题


So I've got the latest versions of jQuery and UI running. I'm using the basic autocomplete invocation and returning valid JSON (validated via JSONLint).

    $("input#cust_id").autocomplete({
        source: yoda.app.base + "/assets/cfc/util/autocomplete.cfc?method=cust",
        minLength: 2,
        select: function(event, ui) {
            log(ui.item ? ("Selected: " + ui.item.value + " aka " + ui.item.id) : "Nothing selected, input was " + this.value);
        }
    });

Both the value and label elements of the returned array show up in the list as undefined. I can watch the results returned via Firebug and the JSON is correct there as well. Also, while the list only says "undefined" it does say that the same number of times as records returned in JSON.

[{"VALUE":"custid1","LABEL":"My Customer Name 1"},{"VALUE":"custname2","LABEL":"My customer name 2"}]

回答1:


Your JSON needs to look like this:

[{value:"custid1",label:"My Customer Name 1"},{value:"custname2",label:"My customer name 2"}]

as keys are case sensitive:

var obj = {"hello" : "foo"};
alert(obj.HELLO); // undefined
alert(obj.hello); // foo


来源:https://stackoverflow.com/questions/2713642/undefined-results-in-jquery-autocomplete

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!