国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

解析jquery easyui tree異步加載子節點問題

2019-11-19 17:15:25
字體:
來源:轉載
供稿:網友

easyui中的樹可以從標記中建立,也可以通過指定一個URL屬性讀取數據建立。如果想建立一棵異步樹,需要為每個節點指定一個id屬性值,這樣在加載數據時會自動向后臺傳遞id參數。

<ul id="tt"></ul>

編寫前臺代碼:

$('#tt').tree({  url:'/demo2/node/getNodes'  // The url will be mapped to NodeController class and getNodes method});

為測試用,建立一個節點的數據模型:

@Table(name="nodes")public class Node extends ActiveRecordBase{  @Id public Integer id;  @Column public Integer parentId;  @Column public String name;   public boolean hasChildren() throws Exception{    long count = count(Node.class, "parentId=?", new Object[]{id});    return count > 0;  }}

編寫后臺的控制器代碼:

public class NodeController extends ApplicationController{  /**   * get nodes, if the 'id' parameter equals 0 then load the first level nodes,   * otherwise load the children nodes   * @param id the parent node id value   * @return the tree required node json format   * @throws Exception   */  public View getNodes(int id) throws Exception{    List<Node> nodes = null;     if (id == 0){  // return the first level nodes      nodes = Node.findAll(Node.class, "parentId=0 or parentId is null", null);    } else {  // return the children nodes      nodes = Node.findAll(Node.class, "parentId=?", new Object[]{id});    }     List<Map<String,Object>> items = new ArrayList<Map<String,Object>>();    for(Node node: nodes){      Map<String,Object> item = new HashMap<String,Object>();      item.put("id", node.id);      item.put("text", node.name);       // the node has children,       // set the state to 'closed' so the node can asynchronous load children nodes       if (node.hasChildren()){        item.put("state", "closed");      }      items.add(item);    }     return new JsonView(items);  }}

官網例子地址:http://www.jeasyui.com/tutorial/tree/tree2.php

demo下載:easyui-tree2_jb51.rar 

重要的事情說三遍!!!

$('#tt').tree({  method:"POST",  url:'/demo2/node/getNodes'  // The url will be mapped to NodeController class and getNodes method});

method一定要用POST,GET的話要在URL后面用一個變量來做時間戳處理。

method一定要用POST,GET的話要在URL后面用一個變量來做時間戳處理。

method一定要用POST,GET的話要在URL后面用一個變量來做時間戳處理。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 洪洞县| 绵竹市| 循化| 聊城市| 手游| 河间市| 荥经县| 呈贡县| 桓台县| 阿拉善盟| 铜川市| 桑植县| 武城县| 库尔勒市| 胶南市| 中江县| 靖西县| 湘阴县| 光山县| 福鼎市| 滨海县| 乌兰浩特市| 双城市| 万源市| 茂名市| 郧西县| 岢岚县| 合作市| 台前县| 比如县| 定州市| 澄迈县| 商南县| 柏乡县| 阳城县| 响水县| 白山市| 灵石县| 台山市| 曲麻莱县| 铅山县|