【发布时间】:2015-03-23 09:55:59
【问题描述】:
选择2代码:
$(".js-select").select2( {
placeholder: "Select Something",
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('main/get_items') ?>",
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.nume };
})
};
},
},
initSelection : function (element, callback) {
var data = {id: "1", text: "test relation"};
callback(data);
},
});
HTML:
<select class="js-select" name="judet" style="width: 100%" required> </select>
- 第一个问题: 使用 initSelection 不起作用:
代码:
initSelection : function (element, callback) {
var data = {id: "1", text: "test relation"};
callback(data);
},
我看到“测试关系”文本,但是当我提交时,我没有得到 id 的值。
- 第二个问题:
当我尝试从下拉列表中选择 1 项时 .... Select2 初始化搜索 ...我需要 select2 仅在用户输入搜索内容时运行搜索 ...
网页:http://www.my-web-projects.com/ajax/main/table -> 按钮添加 ->下拉选择 1 并选择 2
【问题讨论】:
标签: jquery codeigniter jquery-select2