weixin_33720452 2015-05-28 23:49 采纳率: 0%
浏览 61

强制select2 ajax调用

I have 2 select2 and when one of them changes the other one loads it's content using the built in select2 ajax function, the problem is that in the case only one element comes from the server I want it to be loaded by default, but for what I have seen the ajax call is only executed when opening the select2 in question. Here is the code I run when the first selec2 is changed in order to change the second's data:

$select1.on('change', function () {
    initializeLocationsSelect2($select2, $select1.val(), $template, omId);
});

function initializeLocationsSelect2(tag, s1Value, template, id) {
   tag.val("");
   tag.select2({
        placeholder: "Please Select One",
        minimumInputLength: 0,
        multiple: true,
        tokenSeparators: [","],
        tags: false,
        ajax: {
            url: tag.data('url'),
            dataType: 'json',
            quietMillis: 250,
            data: function (term, page) {
                   return {
                        id: id,
                        value: s1Value
                    };
            },
            results: function (data, page) {
                    return {
                        results: data
                    };
            }
        },
        formatSelection: function (item) {
            return $.format(template.html(), item.text);
        },
        formatResult: function (item) {
                return $.format(template.html(), item.text);
        },
        escapeMarkup: function (m) { return m; }
    });
}

just in case it is relevant, the second select2 is attached to a <hidden> tag

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
    • ¥20 西门子S7-Graph,S7-300,梯形图
    • ¥50 用易语言http 访问不了网页
    • ¥50 safari浏览器fetch提交数据后数据丢失问题
    • ¥15 matlab不知道怎么改,求解答!!
    • ¥15 永磁直线电机的电流环pi调不出来
    • ¥15 用stata实现聚类的代码
    • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
    • ¥20 docker里部署springboot项目,访问不到扬声器
    • ¥15 netty整合springboot之后自动重连失效