jQuery Autocomplete的未定义结果
-
01-10-2019 - |
题
因此,我已经运行了最新版本的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);
}
});
返回数组的值和标签元素都显示为未定义。我可以观看通过Firebug返回的结果,而JSON也是正确的。另外,虽然列表仅表示“未定义”,但确实说与JSON中返回的记录相同的次数。
[{"VALUE":"custid1","LABEL":"My Customer Name 1"},{"VALUE":"custname2","LABEL":"My customer name 2"}]
解决方案
您的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
不隶属于 StackOverflow