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

pull/524/MERGE
还俗二师兄 2026-05-26 01:58:54 +00:00 committed by Gitee
commit 25a67206a6
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 18 additions and 4 deletions

View File

@ -134,7 +134,7 @@
var createOptionList = function (searchList, vObjCol, that) { var createOptionList = function (searchList, vObjCol, that) {
var optionList = []; var optionList = [];
optionList.push(sprintf('<option value="">%s</option>', that.options.formatCommonChoose())); 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) { $.each(searchList, function (key, value) {
optionList.push(sprintf("<option value='" + Fast.api.escape(key) + "' %s>" + Fast.api.escape(value) + "</option>", key == vObjCol.defaultValue ? 'selected' : '')); 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; _initSearch = BootstrapTable.prototype.initSearch;
// 定义通用searchList处理方法 // 定义通用searchList处理方法
$.fn.bootstrapTable.utils.combineSearchList = function (list) { $.fn.bootstrapTable.utils.combineSearchList = function (list, vObjCol, that) {
var searchList = {}; var searchList = {};
if (typeof list !== 'undefined') { if (typeof list !== 'undefined') {
@ -294,7 +294,7 @@
var isAjax = typeof list === 'object' && typeof list.then === 'function'; var isAjax = typeof list === 'object' && typeof list.then === 'function';
if (isFunction) { if (isFunction) {
list = list(); list = list();
} else if (isAjax) { } else if (isAjax && vObjCol) {
$.when(list).done(function (ret) { $.when(list).done(function (ret) {
// 兼容旧版本在data中返回searchlist // 兼容旧版本在data中返回searchlist
if (typeof ret.data.searchlist !== 'undefined') { if (typeof ret.data.searchlist !== 'undefined') {
@ -302,7 +302,21 @@
} else { } else {
list = ret; list = ret;
} }
let optionList = [];
$.each(list, function (key, val) {
if (typeof val !== 'undefined' && val.constructor === Object) {
key = val.id;
vObjCol.nameKey = typeof vObjCol.nameKey === 'undefined' ? 'name' : vObjCol.nameKey
val = val[vObjCol.nameKey];
} else {
key = isArray ? val : key;
}
vObjCol.defaultValue = typeof vObjCol.defaultValue === 'undefined' ? '' : vObjCol.defaultValue
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返回字符串直接渲染自定义搜索栏 // 兼容旧版本searchList返回字符串直接渲染自定义搜索栏
if (typeof list === 'string') { if (typeof list === 'string') {
@ -313,7 +327,7 @@
$.each(list, function (key, val) { $.each(list, function (key, val) {
if (typeof val !== 'undefined' && val.constructor === Object) { if (typeof val !== 'undefined' && val.constructor === Object) {
key = val.id; key = val.id;
val = val.name; val = val[vObjCol.nameKey || 'name'];
} else { } else {
key = isArray ? val : key; key = isArray ? val : key;
} }