jQuery自动完成中未定义的结果

Cre*_*ice 4 jquery jquery-ui jquery-ui-autocomplete

所以我已经运行了最新版本的jQuery和UI.我正在使用基本的自动完成调用并返回有效的JSON(通过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);
        }
    });
Run Code Online (Sandbox Code Playgroud)

返回数组的值和标签元素都在列表中显示为undefined.我可以通过Firebug观察返回的结果,JSON也是正确的.此外,虽然列表只显示"未定义",但它确实表示与JSON中返回的记录相同的次数.

[{"VALUE":"custid1","LABEL":"My Customer Name 1"},{"VALUE":"custname2","LABEL":"My customer name 2"}]
Run Code Online (Sandbox Code Playgroud)

kar*_*m79 6

您的JSON需要如下所示:

[{value:"custid1",label:"My Customer Name 1"},{value:"custname2",label:"My customer name 2"}]
Run Code Online (Sandbox Code Playgroud)

密钥区分大小写:

var obj = {"hello" : "foo"};
alert(obj.HELLO); // undefined
alert(obj.hello); // foo
Run Code Online (Sandbox Code Playgroud)