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返回數(shù)組的鍵值一樣 }, // 選擇結果中的顯示 formatResult: function (item) { return item.name;//注意此處的name },// 搜索列表中的顯示 dropdownCssClass: "bigdrop", // apply css that makes the dropdown taller escapeMarkup: function (m) { return m; } });
另外有需要云服務器可以了解下創(chuàng)新互聯(lián)建站www.chinadenli.net,海內(nèi)外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。
網(wǎng)站欄目:BootStrapselect2動態(tài)改變值的方法-創(chuàng)新互聯(lián)
標題鏈接:http://www.chinadenli.net/article24/dgisje.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供App設計、品牌網(wǎng)站設計、搜索引擎優(yōu)化、網(wǎng)站營銷、動態(tài)網(wǎng)站、網(wǎng)站策劃
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)