Codeigniter + Select2设置默认值以用于编辑表单

时间:2015-03-12 09:57:38

标签: php codeigniter jquery-select2

要填充我的下拉列表,我正在使用ajax来调用函数并获取我想要的记录,然后使用$ .map将id和text更改为我使用的列名。

所有工作都很完美,但现在我仍然坚持如何为下拉列表提供默认值:

$(".js-firme-data-array").select2(  {
        ajax: {
            // The number of milliseconds to wait for the user to stop typing before issuing the ajax request
            delay: 400,
            url: "<?php echo site_url('proiecte/get_firme') ?>",
            dataType: "json",
            cache: "true",

            data: function (params) {
                return {
                q: params.term, // search term
                page: params.page,

                };
            },

            processResults: function (data) {
                return {
                    results: $.map(data, function(obj) {
                        return { id: obj.id, text: obj.denumire };
                    })
                };
            },
        },
    });

1 个答案:

答案 0 :(得分:2)

如果其他人正在寻找解决方案,请找到解决方案:

initSelection : function (element, callback) {
    var data = {id: "your id", text: "your text"};
    callback(data);
},