解析jquery easyui tree異步加載子節(jié)點(diǎn)問題
easyui中的樹可以從標(biāo)記中建立,也可以通過指定一個(gè)URL屬性讀取數(shù)據(jù)建立。如果想建立一棵異步樹,需要為每個(gè)節(jié)點(diǎn)指定一個(gè)id屬性值,這樣在加載數(shù)據(jù)時(shí)會(huì)自動(dòng)向后臺(tái)傳遞id參數(shù)。
<ul id="tt"></ul>
編寫前臺(tái)代碼:
$('#tt').tree({ url:'/demo2/node/getNodes' // The url will be mapped to NodeController class and getNodes method });
為測(cè)試用,建立一個(gè)節(jié)點(diǎn)的數(shù)據(jù)模型:
@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; } }
編寫后臺(tái)的控制器代碼:
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); } }
官網(wǎng)例子地址: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后面用一個(gè)變量來做時(shí)間戳處理。
method一定要用POST,GET的話要在URL后面用一個(gè)變量來做時(shí)間戳處理。
method一定要用POST,GET的話要在URL后面用一個(gè)變量來做時(shí)間戳處理。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- EASYUI TREEGRID異步加載數(shù)據(jù)實(shí)現(xiàn)方法
- jquery easyui中treegrid用法的簡(jiǎn)單實(shí)例
- JQuery Easyui Tree的oncheck事件實(shí)現(xiàn)代碼
- 使用jQuery+EasyUI實(shí)現(xiàn)CheckBoxTree的級(jí)聯(lián)選中特效
- 淺談EasyUI中Treegrid節(jié)點(diǎn)的刪除
- EasyUI Tree+Asp.net實(shí)現(xiàn)權(quán)限樹或目錄樹導(dǎo)航的簡(jiǎn)單實(shí)例
- 淺析jQuery EasyUI中的tree使用指南
- Easyui Treegrid改變默認(rèn)圖標(biāo)的方法
- EasyUi combotree 實(shí)現(xiàn)動(dòng)態(tài)加載樹節(jié)點(diǎn)
- 采用easyui tree編寫簡(jiǎn)單角色權(quán)限代碼的方法
相關(guān)文章
Jquery加載時(shí)從后臺(tái)讀取數(shù)據(jù)綁定到dropdownList實(shí)例
從后臺(tái)讀取數(shù)據(jù)綁定到dropdownList,option選項(xiàng)value動(dòng)態(tài)賦值,具體實(shí)現(xiàn)如下,感興趣的朋友可以參考下哈2013-06-06jQuery 開發(fā)者應(yīng)該注意的9個(gè)錯(cuò)誤
jQuery 開發(fā)者應(yīng)該注意的9個(gè)錯(cuò)誤,使用jquery的朋友可以參考下2012-05-05模仿jQuery each函數(shù)的鏈?zhǔn)秸{(diào)用
模仿jQuery each函數(shù)的鏈?zhǔn)秸{(diào)用實(shí)現(xiàn)代碼。2009-07-07jquery通過visible來判斷標(biāo)簽是否顯示或隱藏
這篇文章主要介紹了jquery如何判斷標(biāo)簽是否顯示或隱藏,使用到了visible屬性,大家可以學(xué)習(xí)下2014-05-05jquery制作的移動(dòng)端購(gòu)物車效果完整示例
這篇文章主要介紹了jquery制作的移動(dòng)端購(gòu)物車效果,結(jié)合完整實(shí)例形式詳細(xì)分析了jQuery移動(dòng)端購(gòu)物車具體功能實(shí)現(xiàn)、數(shù)值計(jì)算、界面布局與顯示效果相關(guān)操作技巧,需要的朋友可以參考下2020-02-02使用jQuery實(shí)現(xiàn)驗(yàn)證上傳圖片的格式與大小
在項(xiàng)目中,我們經(jīng)常要遇到上傳圖片,這就需要我們必須要驗(yàn)證圖片的格式與大小,那么如何來操作呢,今天就給大家分享一個(gè)非常簡(jiǎn)單的jQuery驗(yàn)證上傳圖片的格式與大小的代碼。2014-12-12