樹形下拉框 動態加載 數據


在網上找了好久的列子, 終於找到一個,

前台頁面

 1 <script type="text/javascript">
 2         $(function () {
 3 $("#ProductId").combotree({
 4                 required: true
 5             }).combotree("tree").tree({
 6                 url: '/SeekSupplyInfo/ProductList',
 7                 checkbox: false,
 8                 onBeforeExpand: function (node, param) {
 9                     $(this).tree('options').url = "/SeekSupplyInfo/ProductList?id=" + node.id;
10                 }
11             });
12 });
13 </script>
14 
15 <input id="ProductId" name="ProductId">

后台代碼:

這里用的是自己寫一個接口,是獲得父節點列表

   public ActionResult ProductList(string id)
        {
            var data = BusinessLogicFactory.GetLogicInstance<IProductLogic>().GetChildrenNode(id);
            return Json(data);
        }

數據層:

 public IList<Product> GetChildrenNode(string id)
        {
            //當是根節點的時候
            if (id == "root" || string.IsNullOrEmpty(id))
            {
                return DbQuery.Where(d => string.IsNullOrEmpty(d.ParentId)).OrderBy(d => d.Sort).ToList();
            }
            else
            {
                return DbQuery.Where(d => d.ParentId == id).OrderBy(d => d.Sort).ToList();
            }
        }

邏輯層:

 1  public List<ProductTreeModel> GetChildrenNode(string id)
 2         {
 3             List<ProductTreeModel> result = new List<ProductTreeModel>();
 4             var children = repository.GetChildrenNode(id);
 5             foreach (var item in children)
 6             {
 7                 ProductTreeModel model = new ProductTreeModel
 8                 {
 9                     id = item.Id,
10                     text = item.Name
11                 };
12                 if (HaveChildren(item.Id))
13                 {
14                     model.state = "closed";
15                 }
16                 result.Add(model);
17             }
18             return result;
19         }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM