layui-tree添加选择框功能

//勾选框

Tree.prototype.checkbox = function(elem, item){

  var that = this, options = that.options;

  var a = elem.children('a');

  var box = elem.children('.layui-tree-check');


  var checked = function () { 

    if(elem.data('checked')==='yes'){

      var childBox = elem.children('ul').find('.layui-tree-check');

      elem.data('checked','no');

      box.html(icon.checkbox[0]);

      childBox.html(icon.checkbox[0])

              .parent().data('checked','no');

    }else{

      var parentBox = elem.parent('ul')

                          .parentsUntil($(options.elem).parent(),'li')

                          .find('.layui-tree-check:first');

      elem.data('checked','yes');

      box.html(icon.checkbox[1]);

      parentBox.html(icon.checkbox[1])

        .parent().data('checked','yes');

    }

  };

  box.on('click', checked);

  // 单击选中

  if(options.clickToChecked===true){

    a.on('click',checked);

  }

  };

你可能感兴趣的:(layui-tree添加选择框功能)