【问题标题】:X-editable and Select2 with remote data not workingX-editable 和 Select2 远程数据不起作用
【发布时间】:2015-07-01 00:46:20
【问题描述】:

我正在尝试使 x-editableselect2 与远程搜索一起使用。

这是带有 Blade 模板的 HTML。表 id 是“table”。

<td>
    <a href="#" id="{{ $template->id }}" data-value="{{ $template->food_item_id }}" name="food_item" data-type="select2" data-pk="{{ $template->id }}" data-title="" class="editable-click food_item">
        {{ $template->food_item_name }}
   </a>
</td>

我正在使用选择器来设置 x-editable

    $('#table').editable({
        selector: 'tbody tr td .food_item',
        url: '/update',

        select2: {
            cacheDataSource: true,
            allowClear: true,
            placeholder: 'Select food item',
            width: '200px',
            id: function (item) {
                return item.id;
            },
            ajax: {
                url: '/json',
                dataType: "json",
                type: 'post',
                data: function(term, page) {
                  return {
                    q: term
                  };
                },
                results: function(data, page) {
                  return {
                    results: data
                  };
                }
            }
        }
    });

远程 JSON 格式如下:

[{"id":"1","text":"Jasmine Tea"},{"id":"2","text":"Green Tea"},{"id":"3","text":"Herbal Tea"},{"id":"4","text":"Tulsi Tea"},{"id":"5","text":"Chamomile Tea"},{"id":"6","text":"Mint Tea"},{"id":"7","text":"Ginger Green Tea"}]

我只知道

没有找到结果

感谢任何帮助完成这项工作。

【问题讨论】:

标签: jquery json jquery-select2 x-editable


【解决方案1】:

您必须更改 JSON。

记得创建对象结果

例子:

{"results":[{"id":145,"text":" CHECKER "},{"id":146,"text":" CHEROCKE"},
{"id":147,"text":" CHERY "},{"id":148,"text":" CHEVROLET "},
{"id":410,"text":" JINCHENG"},{"id":502,"text":" MARCHETTI "},
{"id":511,"text":" MATCHELSS "},{"id":664,"text":" SAIC CHERY"},
{"id":680,"text":" SCHEUERLE WABCO "},{"id":853,"text":" WINCHEMG"}]}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-23
    • 1970-01-01
    • 2015-07-28
    • 2015-12-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多