mirror of https://github.com/layui/layui
优化 table 模板解析
parent
1fe8b21447
commit
bd2994ec3a
|
@ -77,6 +77,16 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
|
|||
return config || null;
|
||||
};
|
||||
|
||||
// lay 函数可以处理 Selector,HTMLElement,JQuery 类型
|
||||
// 无效的 CSS 选择器字符串,会抛出 SyntaxError 异常,此时直接返回 laytpl 模板字符串
|
||||
var resolveTplStr = function(templet){
|
||||
try{
|
||||
return lay(templet).html();
|
||||
}catch{
|
||||
return templet;
|
||||
}
|
||||
}
|
||||
|
||||
// 解析自定义模板数据
|
||||
var parseTempData = function(obj){
|
||||
obj = obj || {};
|
||||
|
@ -95,9 +105,10 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
|
|||
|
||||
// 获取模板内容
|
||||
if(templet){
|
||||
content = typeof templet === 'function'
|
||||
? templet.call(item3, obj.tplData, obj.obj)
|
||||
: laytpl((templet[0] === '#' ? $(templet).html() : templet) || String(content)).render($.extend({
|
||||
if(typeof templet === 'function'){
|
||||
templet = templet.call(item3, obj.tplData, obj.obj);
|
||||
}
|
||||
content = laytpl(resolveTplStr(templet) || String(content)).render($.extend({
|
||||
LAY_COL: item3
|
||||
}, obj.tplData));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue