优化 dropdown 初始化方法相关代码

pull/1216/head
贤心 2023-03-19 22:37:57 +08:00
parent 461ae352b8
commit 9c6a0a8182
1 changed files with 9 additions and 9 deletions

View File

@ -89,13 +89,13 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
that.init(true); that.init(true);
}; };
//初始化准备 // 初始化准备
Class.prototype.init = function(rerender){ Class.prototype.init = function(rerender){
var that = this var that = this;
,options = that.config var options = that.config;
,elem = options.elem = $(options.elem); var elem = options.elem = $(options.elem);
//若 elem 非唯一 // 若 elem 非唯一
if(elem.length > 1){ if(elem.length > 1){
layui.each(elem, function(){ layui.each(elem, function(){
dropdown.render($.extend({}, options, { dropdown.render($.extend({}, options, {
@ -105,7 +105,7 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
return that; return that;
} }
//若重复执行 render则视为 reload 处理 // 若重复执行 render则视为 reload 处理
if(!rerender && elem[0] && elem.data(MOD_INDEX)){ if(!rerender && elem[0] && elem.data(MOD_INDEX)){
var newThat = thisModule.getThis(elem.data(MOD_INDEX)); var newThat = thisModule.getThis(elem.data(MOD_INDEX));
if(!newThat) return; if(!newThat) return;
@ -115,11 +115,11 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){
// 初始化 id 属性 - 优先取 options > 元素 id > 自增索引 // 初始化 id 属性 - 优先取 options > 元素 id > 自增索引
options.id = 'id' in options ? options.id : ( options.id = 'id' in options ? options.id : (
options.elem.attr('id') || that.index elem.attr('id') || that.index
); );
if(options.show) that.render(rerender); //初始即显示 if(options.show) that.render(rerender); // 初始即显示
that.events(); //事件 that.events(); // 事件
}; };
//渲染 //渲染