jQuery自动完成中的未定义结果 [英] Undefined Results in jQuery Autocomplete

查看:117
本文介绍了jQuery自动完成中的未定义结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在运行最新版本的jQuery和UI. 我正在使用基本的自动完成调用,并返回有效的JSON(通过JSONLint验证).

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);
        }
    });

返回数组的value和label元素在列表中均显示为undefined. 我可以观看通过Firebug返回的结果,那里的JSON也正确.此外,虽然列表只说未定义",但确实说的次数与JSON中返回的记录的次数相同.

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"}]

推荐答案

您的JSON需要看起来像这样:

Your JSON needs to look like this:

[{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

这篇关于jQuery自动完成中的未定义结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆