国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

BootStrap select2 動態(tài)改變值的方法

2019-11-19 17:38:17
字體:
來源:轉載
供稿:網友

1,selec2動態(tài)賦值

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,動態(tài)改變值                                             

$("#e_pid").attr("value", temp);                          $("#e_pid").trigger('change'); //動態(tài)改變值以后必須觸發(fā)改變時間。否則將不會生效

以上所述是小編給大家介紹的BootStrap select2 動態(tài)改變值的方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 大埔县| 铁力市| 温宿县| 稷山县| 贺州市| 宝应县| 若尔盖县| 兴宁市| 内江市| 广南县| 清流县| 镶黄旗| 广元市| 武乡县| 天气| 团风县| 新化县| 汽车| 博罗县| 高邮市| 武汉市| 鄂伦春自治旗| 衡水市| 柘城县| 闽侯县| 揭东县| 临潭县| 汉沽区| 格尔木市| 会昌县| 乐亭县| 洪雅县| 永清县| 崇左市| 怀化市| 平泉县| 东乌珠穆沁旗| 墨玉县| 墨玉县| 石柱| 大同市|