四虎精品视频-四虎精品成人免费网站-四虎黄色网-四虎国产视频-国产免费91-国产蜜臀97一区二区三区

學(xué)習(xí)YUI.Ext 第六天--關(guān)于樹(shù)TreePanel(Part 1)

學(xué)習(xí)YUI.Ext 第五天--關(guān)于樹(shù)TreePanel(Part 1) 
效果演示:http://www.ajaxjs.com/yuicn/demos/order_tree.ASP
    樹(shù)組件是YUI.Ext 0.40 新增的組件。雖然YUI已經(jīng)自帶有TREE VIEW的組件,但JACK還是決定重新開(kāi)發(fā)。具體原因在http://www.ajaxjs.com/yuicn/article.ASP?id=20070245(翻譯文章)或http://www.jackslocum.com/blog/2006/12/29/preview-drag-and-drop-enhancements-and-the-new-treepanel/ (原文) 
一、加載一個(gè)同步Tree:
復(fù)制代碼 代碼如下:
var TreeTest = function(){ 
var Tree = YAHOO.ext.tree;// 快捷方式 
return { 
    init : function(){ 
    var tree = new Tree.TreePanel('tree_div', {//需要一個(gè)tree_div的holder 
    animate:true, //是否動(dòng)畫(huà) 
    loader: new Tree.TreeLoader({dataUrl:'get_nodes.ASP'}), //調(diào)用一個(gè)JSON 
    enableDD:false,// 是否支持拖放 
    containerScroll: true 
}); 
// 設(shè)置根節(jié)點(diǎn) 
var root = new Tree.AsyncTreeNode({ 
text: 'Frank的作品',  //根節(jié)點(diǎn)文字 
draggable:false, //根節(jié)點(diǎn)是否可拖放 
id:'source' 
}); 
tree.setRootNode(root); 
// 渲染 tree 
tree.render(false,false); 
// false for not recursive (the default), false to disable animation 
root.expand(false,false); 

}; 
}(); 
YAHOO.ext.EventManager.onDocumentReady(TreeTest.init, TreeTest, true);

通過(guò)XHR調(diào)用這個(gè)get_nodes.ASP文件,假設(shè)服務(wù)器返回這樣一個(gè)JSON(有關(guān)JSON的介紹:http://www.json.org/json-zh.html):
[{
"text":"yui-ext.js","id":"http://yui-ext.js","leaf":true,"cls":"file"
} ,{
"text":"yui-ext-1118.php","id":"http://yui-ext-1118.php","leaf":true,"cls":"file"
} ,{
"text":"yui-ext-1228.php","id":"http://yui-ext-1228.php","leaf":true,"cls":"file"
} ,{
"text":"build","id":"http://build","cls":"folder"
} ,{
"text":"source","id":"http://source","cls":"folder"
} ,{
"text":"yui-ext-1123.php","id":"http://yui-ext-1123.php","leaf":true,"cls":"file"
} ,{
"text":"yui-ext-1203.php","id":"http://yui-ext-1203.php","leaf":true,"cls":"file"
} ]
  Server端JSON的輸出(ASP JScript)  

復(fù)制代碼 代碼如下:
var goods = new dbOpen(); 
goods.GetSQL ="select * from goodsbigclass"; 
with(goods){ 
    GetRS(1); 
    var str=""; 
    str+="["; 
    do{ 
        str+='{"text":"'+rs("BigClassName")+'","id":"http://yui-ext.js","leaf":true,"cls":"file","href":"?b_id='+rs("BigClassID")+'"},'; 
        rs.MoveNext(); 
    }while(!rs.EOF); 
    str+="]"; 
    Response.Write(str); 
    Close(); 

goods= null; 

解釋:
“text”-->顯示的文本
"id"-->id值 
“l(fā)eaf”-->Boolean值,如果“葉子”是真的話,則不能包含子節(jié)點(diǎn)Children nodes 
"cls"-->選用的樣式,通常在這里選定圖標(biāo)
”href“-->指定的url,還有一個(gè)”hrefTarget“的屬性
另外,除了以上的屬性,您還可以在JSON加入任何的屬性,作為節(jié)點(diǎn)的屬性,見(jiàn)Jack原話:
The href attribute is called "href", there's also an "hrefTarget" attribute. For capturing node clicks, you can listen on individual nodes or you can listen for "click" on the tree which will pass you the node that was clicked. FYI, you can put any attributes you want in the json config for the node and it will be available as node.attributes. FAQ.4會(huì)繼續(xù)解釋這個(gè)問(wèn)題。
FQA常見(jiàn)問(wèn)題:
1.Tree支持XML數(shù)據(jù)交換嗎?
A:暫不支持,據(jù)FOURM上的話,以后會(huì)提供支持,見(jiàn):
can I use xml instead of json for sending nodes hirerachy ?
Correct me if I'm wrong but I think the answer is no here. But that doesn't mean it won't be supported later on. 
2.我想用單擊代替雙擊展開(kāi)子節(jié)點(diǎn),可以嗎?
A:可以,見(jiàn): 
tree.on('click', function(node){ 
    if(!node.isLeaf()){ 
        node.toggle(); 
    } 
}); 
3.事件處理的幾種情形:
A: a.當(dāng)加入某個(gè)節(jié)點(diǎn)時(shí),為其增加事件 
tree.on('append', function(tree, node){ 
     if(node.id == 'foo'){ 
         // 這里加入你的事件(如click)偵聽(tīng)器(addListener())
     } 
});b.針對(duì)某個(gè)節(jié)點(diǎn)的單擊事件 
tree.on('click', function(node){ 
     if(node.id == 'foo'){ 
         // do something 
     } 
});c.針對(duì)某個(gè)區(qū)域(集合)的事件 
// fires any time the selection in the tree changes 
tree.getSelectionModel().on('selectionchange', function(sm, node){ 
     if(node && node.id == 'foo'){ 
         // do something 
     } 
}); 
4.如何獲取JSON中的自定義字段(或稱作參數(shù) parameters)
A:JSON對(duì)象已經(jīng)被構(gòu)建函數(shù) construction傳遞到TreeNode中,作為node.attributes 出現(xiàn),所以調(diào)用屬性node.attributes 便可獲取。詳見(jiàn):http://www.yui-ext.com/forum/viewtopic.php?t=2253 
tree.on('click', function(node){ 
    if(!node.isLeaf()){ 
        node.toggle(); 
    } 
});

JavaScript技術(shù)學(xué)習(xí)YUI.Ext 第六天--關(guān)于樹(shù)TreePanel(Part 1),轉(zhuǎn)載需保留來(lái)源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 美女洗澡直播| 朱莉娅·安最经典十部电影| 变态的视频| 光棍电影| 赵士杰| 何育骏| 贤惠好儿媳在线观看完整版| 被打屁股视频| 昵称大全2024最新版| 捷克女人性ⅹxxxx视频| cctv16节目表今天目表| 七年级的英语翻译全书| 周星驰原名| xiee| 陈慧娴个人资料| 一江深情简谱| 日韩欧美视频在线播放| 树屋轻调| 张梓琳个人简历| 感谢有你简谱| 啪啪电影网| 赫伯曼电影免费观看| 漂亮孕妇突然肚子疼视频| 工会基层组织选举工作条例| 夜色斗僵尸| 俺去也电影网| 古宅老友记第四季| led灯修复方法视频| 抖音在线观看| 春闺梦里人演员表| 国家宝藏电影| 我的朋友作文| 大珍珠演员表介绍| 喜羊羊简谱| 韩国电影血色对决免费观看| 美国伦理小樱桃1| 消防给水及消火栓系统技术规范| 女攻男受文| 美丽女波士1983| 服务群众方面整改成效| 冷门森系ins冷淡风壁纸|