优化 `form.render()` 方法

pull/1194/head
贤心 2023-01-13 03:45:30 +08:00
parent a9a2b24f49
commit a3154b6623
1 changed files with 32 additions and 21 deletions

View File

@ -745,13 +745,25 @@ layui.define(['layer', 'util'], function(exports){
});
}
};
if (layui.type(type) === 'object') {
// 执行所有渲染项
var renderItem = function(){
layui.each(items, function(index, item){
item();
});
};
// jquery 对象
if (layui.type(type) === 'object') {
// 若对象为表单域容器
if($(type).is(ELEM)){
elemForm = $(type);
renderItem();
} else { // 对象为表单项
type.each(function (index, item) {
var elem = $(item);
if (!elem.closest(ELEM).length) {
// 如果不是存在layui-form中的直接跳过
return;
return; // 若不在 layui-form 容器中直接跳过
}
if (item.tagName === 'SELECT') {
items['select'](elem);
@ -764,12 +776,11 @@ layui.define(['layer', 'util'], function(exports){
}
}
});
}
} else {
type ? (
items[type] ? items[type]() : hint.error('不支持的 "'+ type + '" 表单渲染')
) : layui.each(items, function(index, item){
item();
});
) : renderItem();
}
return that;
};