select2 ajax将不显示返回的json数据 [英] select2 ajax won't display json data returned

查看:234
本文介绍了select2 ajax将不显示返回的json数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是从我的ColdFusion页面:[{"client":"Asante","id":12},{"client":"City of Lancaster","id":14},{"client":"Massey Energy","id":35},{"client":"Northeast Utilities","id":68},{"client":"Washtenaw","id":50}]返回的json字符串的样子. Firebug声称一切正常,但是select2插件中没有显示任何数据.

Here is what the json string looks like that gets returned from my coldfusion page: [{"client":"Asante","id":12},{"client":"City of Lancaster","id":14},{"client":"Massey Energy","id":35},{"client":"Northeast Utilities","id":68},{"client":"Washtenaw","id":50}]. Firebug claims everything is working perfectly but none of the data shows up in the select2 plugin.

有人知道这个问题可能是什么吗?它应该返回列名还是什么?

Does anyone know what the problem might be? Should it be returning column names or something?

select2通话:

select2 call:

$(".select").select2({
    allowClear: true,
    blurOnChange: true,
    openOnEnter: false,
    ajax: {
        url: "/surveymanagement/admin/client.cfc",
        dataType: 'json',
        data: function (term, page) {
            return {
                method: "GetClientsByName",
                name: term
            };
        },
        results: function (data, page) {
            return { results: data };
        }
    }
});

推荐答案

您的数据必须为[{"text":"Asante","id":12}, ...]格式,否则您需要传递{results: data, text: 'client'}

Your data must of format [{"text":"Asante","id":12}, ...] else you need to pass {results: data, text: 'client'}

这篇关于select2 ajax将不显示返回的json数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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