对text、title、confirm进行模板数据替换

pull/140/head
qlo1062 2019-08-21 11:06:01 +08:00
parent ebf38b470c
commit d4db5fe996
1 changed files with 26 additions and 2 deletions

View File

@ -639,11 +639,13 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
url = typeof url === 'function' ? url.call(table, row, j) : (url ? Fast.api.fixurl(Table.api.replaceurl(url, row, table)) : 'javascript:;');
classname = j.classname ? j.classname : 'btn-primary btn-' + name + 'one';
icon = j.icon ? j.icon : '';
text = typeof j.text === 'function' ? j.text.call(table, row, j) : j.text ? j.text : '';
title = typeof j.title === 'function' ? j.title.call(table, row, j) : j.title ? j.title : text;
text = typeof j.text === 'function' ? j.text.call(table, row, j) : j.text ? Table.api.replacetplval(text, row, table) : '';
title = typeof j.title === 'function' ? j.title.call(table, row, j) : j.title ? Table.api.replacetplval(title, row, table) : text;
refresh = j.refresh ? 'data-refresh="' + j.refresh + '"' : '';
confirm = typeof j.confirm === 'function' ? j.confirm.call(table, row, j) : (typeof j.confirm !== 'undefined' ? j.confirm : false);
confirm = Table.api.replacetplval(confirm, row, table);
confirm = confirm ? 'data-confirm="' + confirm + '"' : '';
extend = j.extend ? j.extend : '';
disable = typeof j.disable === 'function' ? j.disable.call(table, row, j) : (typeof j.disable !== 'undefined' ? j.disable : false);
if (disable) {
@ -692,6 +694,28 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
});
return url;
},
//替换模板数据
replacetplval: function (text, row, table) {
var options = table ? table.bootstrapTable('getOptions') : null;
var ids = options ? row[options.pk] : 0;
row.ids = ids ? ids : (typeof row.ids !== 'undefined' ? row.ids : 0);
text = text ? text : "";
text = text.replace(/\{(.*?)\}/gi, function (matched) {
matched = matched.substring(1, matched.length - 1);
if (matched.indexOf(".") !== -1) {
var temp = row;
var arr = matched.split(/\./);
for (var i = 0; i < arr.length; i++) {
if (typeof temp[arr[i]] !== 'undefined') {
temp = temp[arr[i]];
}
}
return typeof temp === 'object' ? '' : temp;
}
return row[matched];
});
return text;
},
// 获取选中的条目ID集合
selectedids: function (table) {
var options = table.bootstrapTable('getOptions');