From 0ca0fddca354a087827488b1076b8b1498aeb337 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A4=E5=BF=83?= <3277200+sentsim@users.noreply.github.com> Date: Sat, 22 Apr 2023 17:24:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20dropdown=20=E7=9A=84=20`te?= =?UTF-8?q?mplet`=20=E5=B1=9E=E6=80=A7=EF=BC=8C=E4=BB=A5=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E5=86=99=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/dropdown.js | 44 +++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/src/modules/dropdown.js b/src/modules/dropdown.js index 60425d65..247e9bee 100644 --- a/src/modules/dropdown.js +++ b/src/modules/dropdown.js @@ -130,36 +130,42 @@ layui.define(['jquery', 'laytpl', 'lay'], function(exports){ that.events(); // 事件 }; - //渲染 + // 渲染 Class.prototype.render = function(rerender, type){ - var that = this - ,options = that.config - ,elemBody = $('body') + var that = this; + var options = that.config; + var elemBody = $('body'); - //默认菜单内容 - ,getDefaultView = function(){ + // 默认菜单内容 + var getDefaultView = function(){ var elemUl = $(''); if(options.data.length > 0 ){ eachItemView(elemUl, options.data) } else { - elemUl.html('
  • no menu
  • '); + elemUl.html('
  • No data
  • '); } return elemUl; - } + }; - //遍历菜单项 - ,eachItemView = function(views, data){ - //var views = []; + // 遍历菜单项 + var eachItemView = function(views, data){ + // var views = []; layui.each(data, function(index, item){ - //是否存在子级 - var isChild = item.child && item.child.length > 0 - ,isSpreadItem = ('isSpreadItem' in item) ? item.isSpreadItem : options.isSpreadItem - ,title = item.templet - ? laytpl(item.templet).render(item) - : (options.templet ? laytpl(options.templet).render(item) : item.title) + // 是否存在子级 + var isChild = item.child && item.child.length > 0; + var isSpreadItem = ('isSpreadItem' in item) ? item.isSpreadItem : options.isSpreadItem + var title = function(title){ + var templet = item.templet || options.templet; + if(templet){ + title = typeof templet === 'function' + ? templet(item) + : laytpl(templet).render(item); + } + return title; + }(item.title); - //初始类型 - ,type = function(){ + // 初始类型 + var type = function(){ if(isChild){ item.type = item.type || 'parent'; }