Repository: sentsin/layui
File: src/modules/dropdown.js (JavaScript)

Code before:
          if(type === 'parent'){
            elemPanel.append(eachItemView(elemUl, item[customName.children]));
            viewLi.append(elemPanel);
          } else {
            viewLi.append(eachItemView(elemUl, item[customName.children]));
          }
        }

        views.append(viewLi);
      });
      return views;
    };
    
    // 主模板
    var TPL_MAIN = [
      '<div class="layui-dropdown layui-border-box layui-panel layui-anim layui-anim-downbit" ' + MOD_ID + '="' + options.id + '">',
      '</div>'
    ].join('');

    // 重载或插入面板内容
    var content = options.content || getDefaultView();
    var mainElemExisted = $('.' + STR_ELEM + '[' + MOD_ID + '="' + options.id + '"]');
    if (type === 'reloadData' && mainElemExisted.length) { // // 是否仅重载数据
      var mainElem = that.mainElem = mainElemExisted;
      mainElemExisted.html(content);
    } else { // 常规渲染
      var mainElem = that.mainElem = $(TPL_MAIN);
      mainElem.append(content);

      // 初始化某些属性
      mainElem.addClass(options.className);
      mainElem.attr('style', options.style);

      // 辞旧迎新
      that.remove(dropdown.thisId);
      bodyElem.append(mainElem);

      // 遮罩
      var shade = options.shade ? ('<div class="'+ STR_ELEM_SHADE +'" style="'+ ('z-index:'+ (mainElem.css('z-index')-1) +'; background-color: ' + (options.shade[1] || '#000') + '; opacity: ' + (options.shade[0] || options.shade)) +'"></div>') : '';
      mainElem.before(shade);

      // 如果是鼠标移入事件，则鼠标移出时自动关闭
      if(options.trigger === 'mouseenter'){
        mainElem.on('mouseenter', function(){
          clearTimeout(thisModule.timer);
        }).on('mouseleave', function(){
          that.delayRemove();
        });
      }
    }


Review comment (suggestion):
```suggestion
      that.mainElem = mainElemExisted;
```


Code after:
          var elemUl = $('<ul></ul>');

          if(type === 'parent'){
            elemPanel.append(eachItemView(elemUl, item[customName.children]));
            viewLi.append(elemPanel);
          } else {
            viewLi.append(eachItemView(elemUl, item[customName.children]));
          }
        }

        views.append(viewLi);
      });
      return views;
    };
    
    // 主模板
    var TPL_MAIN = [
      '<div class="layui-dropdown layui-border-box layui-panel layui-anim layui-anim-downbit" ' + MOD_ID + '="' + options.id + '">',
      '</div>'
    ].join('');

    // 重载或插入面板内容
    var content = options.content || getDefaultView();
    var mainElemExisted = thisModule.findMainElem(options.id);
    if (type === 'reloadData' && mainElemExisted.length) { // 是否仅重载数据
      var mainElem = that.mainElem = mainElemExisted;
      mainElemExisted.html(content);
    } else { // 常规渲染
      var mainElem = that.mainElem = $(TPL_MAIN);
      mainElem.append(content);

      // 初始化某些属性
      mainElem.addClass(options.className);
      mainElem.attr('style', options.style);

      // 辞旧迎新
      that.remove(dropdown.thisId);
      bodyElem.append(mainElem);
      options.elem.data(MOD_INDEX_OPENED, true); // 面板已打开的标记

      // 遮罩
      var shade = options.shade ? ('<div class="'+ STR_ELEM_SHADE +'" style="'+ ('z-index:'+ (mainElem.css('z-index')-1) +'; background-color: ' + (options.shade[1] || '#000') + '; opacity: ' + (options.shade[0] || options.shade)) +'"></div>') : '';
      mainElem.before(shade);

      // 如果是鼠标移入事件，则鼠标移出时自动关闭
      if(options.trigger === 'mouseenter'){
        mainElem.on('mouseenter', function(){
          clearTimeout(thisModule.timer);
        }).on('mouseleave', function(){
          that.delayRemove();
        });