Jquery樹控制項ZTree非同步載入

來源:互聯網
上載者:User

標籤:class   設計   ++   out   過濾   alt   實現   需要   意思   

非同步載入的意思就是: 當點擊展開樹節點時,才去請求後台action返回點擊節點的子節點資料並載入。

這裡面主要設計ztree的setting變數的async屬性設定:

var setting = {       async: {           enable: true,           url:InitServiceIpsData.action,           autoParam:[id, name],           dataFilter: filter             },

當點擊展開樹節點時,會請求url指定的action擷取子節點資料,然後綁定到ztree上。

注意這裡後台action返回的是JSON字串,而ztree綁定新的節點資料只接收數組,所以需要在綁定前用filter函數進行資料清洗轉換操作,將字串轉換為數組:

//過濾非同步載入ztree時返回的資料function filter(treeId, parentNode, childNodes) {    if (!childNodes)        return null;             childNodes = eval((+childNodes+));  //必須轉換為[{id:103,pId:1,name:‘子節點3‘}];這樣的格式        return childNodes;}

這樣點擊展開ztree樹節點時,就會請求action擷取子節點資料並綁定了。

下面是後台action的一個實現:

public String InitServiceIpsData()    {        HttpServletRequest request = ServletActionContext.getRequest();        String id = request.getParameter(id);        String name = request.getParameter(name);        System.out.println(請求擷取+name+的ip列表);                 List<hashmap<string,object>> list = new ArrayList<hashmap<string,object>>();                  for(int i = 1; i <= 2; i++){              HashMap<string,object> hm = new HashMap<string,object>();                        hm.put(id, id + 0 + i);            hm.put(pId, id);            hm.put(name, name + _IP_ + i);            hm.put(isParent, false);            list.add(hm);        }                     JSONArray finalJson = JSONArray.fromObject(list);        this.initServiceIpsData = finalJson.toString();        return SUCCESS;    }

  

Jquery樹控制項ZTree非同步載入

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.