Pre Merge pull request !524 from 还俗二师兄/commonsearch

还俗二师兄 2026-05-11 02:44:07 +00:00 committed by Gitee
commit 82c5a7e5e2
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 15 additions and 3 deletions

View File

@ -134,7 +134,7 @@
var createOptionList = function (searchList, vObjCol, that) {
var optionList = [];
optionList.push(sprintf('<option value="">%s</option>', that.options.formatCommonChoose()));
searchList = $.fn.bootstrapTable.utils.combineSearchList(searchList);
searchList = $.fn.bootstrapTable.utils.combineSearchList(searchList, vObjCol, that);
$.each(searchList, function (key, value) {
optionList.push(sprintf("<option value='" + Fast.api.escape(key) + "' %s>" + Fast.api.escape(value) + "</option>", key == vObjCol.defaultValue ? 'selected' : ''));
});
@ -286,7 +286,7 @@
_initSearch = BootstrapTable.prototype.initSearch;
// 定义通用searchList处理方法
$.fn.bootstrapTable.utils.combineSearchList = function (list) {
$.fn.bootstrapTable.utils.combineSearchList = function (list, vObjCol, that) {
var searchList = {};
if (typeof list !== 'undefined') {
@ -302,7 +302,19 @@
} else {
list = ret;
}
let optionList = [];
$.each(list, function (key, val) {
if (typeof val !== 'undefined' && val.constructor === Object) {
key = val.id;
val = val[vObjCol.nameKey || 'name'];
} else {
key = isArray ? val : key;
}
optionList.push(sprintf("<option value='" + Fast.api.escape(key) + "' %s>" + Fast.api.escape(val) + "</option>", key == vObjCol.defaultValue && vObjCol.defaultValue !='' ? 'selected' : ''));
});
$("form.form-commonsearch select[name='" + vObjCol.field + "']", that.$container).append(optionList.join('')).trigger("change");
});
list = '';
}
// 兼容旧版本searchList返回字符串直接渲染自定义搜索栏
if (typeof list === 'string') {
@ -313,7 +325,7 @@
$.each(list, function (key, val) {
if (typeof val !== 'undefined' && val.constructor === Object) {
key = val.id;
val = val.name;
val = val[vObjCol.nameKey || 'name'];
} else {
key = isArray ? val : key;
}