bootstrap select2 动态改变值
来源:互联网 发布:java开发app 编辑:程序博客网 时间:2024/04/26 01:34
1,selec2动态赋值
var temp=JSON.stringify({ id: "1|所有停车场", name: "所有停车场" });
$("#e_pid").attr("value", tempP);
$("#e_pid").select2({
placeholder: "查找停车场名称(多选)",
language: "zh-CN",
minimumInputLength: 1,
allowClear: true,
multiple: true,
ajax: {
// instead of writing the function to execute the request we use Select2's convenient helper
url: "/manage/park/index/json/index",
dataType: 'json',
data: function (term, page) {
return {
parkName: term,// search term
powerpid: "1"
};
},
results: function (data, page) { // parse the results into the format expected by Select2.
// since we are using custom formatting functions we do not need to alter remote JSON data
for (var i = 0; i < data.length; i++) {
data[i].id = data[i].id+"|"+data[i].name;
};
data.push({ id: "577cb125f8d2c404572413d1|无", name: "无" });
return {
results: data
};
}
},
initSelection: function (element, callback) {
//赋初始值
// the input tag has a value attribute preloaded that points to a preselected movie's id
// this function resolves that id attribute to an object that select2 can render
// using its formatResult renderer - that way the movie name is shown preselected
var data = [];
var value = ""
var str = $(element).val().split('^');
for (var i = 0; i < str.length; i++) {
var temp = JSON.parse(str[i]);
value += temp.id + ",";
data.push(temp);
}
;
value = value.substring(0, value.length - 1);
$(element).val(value);
callback(data);
},
formatSelection: function (item) {
return item.name;//注意此处的name,要和ajax返回数组的键值一样
}, // 选择结果中的显示
formatResult: function (item) {
return item.name;//注意此处的name
},// 搜索列表中的显示
dropdownCssClass: "bigdrop", // apply css that makes the dropdown taller
escapeMarkup: function (m) {
return m;
}
});
2,动态改变值
$("#e_pid").attr("value", temp);
$("#e_pid").trigger('change'); //动态改变值以后必须触发改变时间。否则将不会生效
- bootstrap select2 动态改变值
- bootstrap select2 动态改变值
- select2 bootstrap 简单使用
- select2 bootstrap 简单使用
- select2插件 多选框动态初始化值
- bootstrap select2默认选中后台传过来的值
- select2与Bootstrap冲突解决
- bootstrap与Select2使用小结
- select2.4.0 动态搜索
- 在BootStrap的modal中使用Select2
- select2搜索框无法输入 Bootstrap 模态框
- select2控件动态更新option
- bootstrap 实现弹出框popover,动态改变popover内容
- bootstrap editable 动态改变列的编辑状态
- bootstrap editable 动态改变列的编辑状态
- bootstrap模态框弹出和隐藏,动态改变中间内容
- select2固定值使用
- Select2 如何设置值?
- 选中一行或多行的快捷键
- 测试apsx与aspx.cs 关系
- 用正则表达式统计java工作行,注释行,空白行
- python进行基本的图像处理
- mysql数据库数据类型
- bootstrap select2 动态改变值
- HDU 5923 Prediction (并查集)
- 怎样编辑pdf文件的重点部分
- Android-6步教你自定义View
- RBAC数据库的设计
- 463. Island Perimeter | 岛屿的周长
- 回忆之前丢掉的两个点
- ios适配
- 利用仿函数实现定制删除器