BootStrap select2 动态改变值的方法

前端之家收集整理的这篇文章主要介绍了BootStrap select2 动态改变值的方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1,selec2动态赋值

名称(多选)",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,动态改变值

以上所述是小编给大家介绍的BootStrap select2 动态改变值的方法。编程之家 jb51.cc 收集整理的教程希望能对你有所帮助,如果觉得编程之家不错,可分享给好友!感谢支持

原文链接:https://www.f2er.com/bootstrap/41806.html

猜你在找的Bootstrap相关文章