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

时间:2010-04-26 13:11:14

标签: 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);
        }
    });

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

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

1 个答案:

答案 0 :(得分:6)

您的JSON需要如下所示:

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

因为键区分大小写:

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