bootstrap table 行内编辑Select2多选 需要修改bootstrap-editable.js源码的itemsByValue方法
当多选时,回传类似 ",1,2,3"的字符串,需要转换成数组
var columns = [{ title : '列名', field : 'zpyq', align : 'center', width : "25%", editable : { type : 'select2', title : '列名', name : 'zpyq', emptytext : "--", placement : 'top', source : function() {//动态获取数据 var result = []; $.Ajax({ url : $.el.Register.AppUrl + "rwfp/selectZjyqB", async : false, type : "get", data : {}, success : function(data, status) { $.each(data, function(key, value) { result.push({ value : value.id, text : value.zkyq }); }); } }); return result; }, inputclass : 'input-large', select2 : { allowClear : true, multiple : true,//多选 tokenSeparators : [",", " "], width : '150px'//设置宽 } } }]bootstrap-editable.js源码修改
itemsByValue : function(value, sourceData, valuePRop) { if (!sourceData || value === null) { return []; } if (typeof(valueProp) !== "function") { var idKey = valueProp || 'value'; valueProp = function(e) { return e[idKey]; }; } /** * @author ZhangZhi 2017-02-05 * 行内编辑select2多选设置 */ value += ""; if (value.substr(0, 1) == ',') value = value.substr(1); value = value.split(','); /** * 修改结束 */ var isValArray = $.isArray(value), result = [], that = this;
新闻热点
疑难解答