easyui tree加上复选框CheckBox 简单方法

版权声明:本文为博主原创文章,如需转载请附出处。 https://blog.csdn.net/CommandBaby/article/details/20934223
<ul id="et" class="easyui-tree">  
  </ul> 


 $(function () {

            $('#et').tree({
                url: 'http://localhost:2148/Main/GetMenu',
                checkbox: true
            });

public JsonResult GetMenu()  
       {  
           //格式必须是一个集合  
           List<TreeModel> litm = new List<TreeModel>();  
  
           TreeModel mf = new TreeModel();//父节点  
           mf.id = "id";  
           mf.text = "管理";  
  
           List<TreeChildrenModel> li = new List<TreeChildrenModel>();//子节点  
           foreach (var item in List)  
           {  
               TreeChildrenModel tcm = new TreeChildrenModel();  
               tcm.id = item.id.ToString();  
               tcm.text = item.title;  
               tcm.@checked = true;  
               tcm.attributes = new Attributes() { url = "" };  
               li.Add(tcm);  
           }  
           mf.children = li;  
           litm.Add(mf);  
  
           return Json(litm);  
       }  
   }  
 
   #region easy ui 动态树需要model  
   public class TreeModel  
   {  
       public string id { get; set; }  
       public string text { get; set; }  
       public bool @checked { get; set; }  
       public List<TreeChildrenModel> children { get; set; }  
   }  
  
   public class TreeChildrenModel  
   {  
       public string id { get; set; }  
       public string text { get; set; }  
       public bool @checkbox{ get; set; }  
       public Attributes attributes { get; set; }  
   }  
  
   public class Attributes  
   {  
       public string url { get; set; }  
   }  
   #endregion  



展开阅读全文

没有更多推荐了,返回首页