<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    菠蘿三國

    大江東去,浪淘盡...
    隨筆 - 34, 文章 - 47, 評論 - 22, 引用 - 0
    數據加載中……

    學習EXT第六天--關于樹TreePanel(Part 1)

    樹組件是YUI.Ext 0.40 新增的組件。雖然YUI已經自帶有TREE VIEW的組件,但JACK還是決定重新開發。具體原因在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/ (原文)

    一、加載一個同步Tree:

    var TreeTest = function(){
    var Tree = YAHOO.ext.tree;// 快捷方式

    return {
    init : function(){
    var tree = new Tree.TreePanel('tree_div', {//需要一個tree_div的holder
    animate:true, //是否動畫
    loader: new Tree.TreeLoader({dataUrl:'get_nodes.asp'}), //調用一個JSON
    enableDD:false,// 是否支持拖放
    containerScroll: true
    });

    // 設置根節點
    var root = new Tree.AsyncTreeNode({
    text: 'Frank的作品', //根節點文字
    draggable:false, //根節點是否可拖放
    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);

    通過XHR調用這個get_nodes.asp文件,假設服務器返回這樣一個JSON(有關JSON的介紹:http://www.json.org/json-zh.html):

    [{
    "text":"yui-ext.js","id":"\/yui-ext.js","leaf":true,"cls":"file"
    } ,{
    "text":"yui-ext-1118.php","id":"\/yui-ext-1118.php","leaf":true,"cls":"file"
    } ,{
    "text":"yui-ext-1228.php","id":"\/yui-ext-1228.php","leaf":true,"cls":"file"
    } ,{
    "text":"build","id":"\/build","cls":"folder"
    } ,{
    "text":"source","id":"\/source","cls":"folder"
    } ,{
    "text":"yui-ext-1123.php","id":"\/yui-ext-1123.php","leaf":true,"cls":"file"
    } ,{
    "text":"yui-ext-1203.php","id":"\/yui-ext-1203.php","leaf":true,"cls":"file"
    } ]
    
    Server端JSON的輸出(ASP JScript)
    var goods = new dbOpen();
    goods.GetSQL ="select * from goodsbigclass";
    with(goods){
    GetRS(1);
    var str="";
    str+="[";
    do{
    str+='{"text":"'+rs("BigClassName")+'","id":"\/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值
    “leaf”-->Boolean值,如果“葉子”是真的話,則不能包含子節點Children nodes
    "cls"-->選用的樣式,通常在這里選定圖標
    ”href“-->指定的url,還有一個”hrefTarget“的屬性
    另外,除了以上的屬性,您還可以在JSON加入任何的屬性,作為節點的屬性,見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會繼續解釋這個問題。
    FQA常見問題:

    1.Tree支持XML數據交換嗎?
    A:暫不支持,據FOURM上的話,以后會提供支持,見:
    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.我想用單擊代替雙擊展開子節點,可以嗎?
    A:可以,見:

    tree.on('click', function(node){
    if(!node.isLeaf()){
    node.toggle();
    }
    });

     

    3.事件處理的幾種情形:
    A: a.當加入某個節點時,為其增加事件

    tree.on('append', function(tree, node){
    if(node.id == 'foo'){
    // 這里加入你的事件(如click)偵聽器(addListener())
    }
    });

    b.針對某個節點的單擊事件

    tree.on('click', function(node){
    if(node.id == 'foo'){
    // do something
    }
    });

    c.針對某個區域(集合)的事件

    // 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中的自定義字段(或稱作參數 parameters)
    A:JSON對象已經被構建函數 construction傳遞到TreeNode中,作為node.attributes 出現,所以調用屬性node.attributes 便可獲取。詳見:http://www.yui-ext.com/forum/viewtopic.php?t=2253

    tree.on('click', function(node){
    if(!node.isLeaf()){
    node.toggle();
    }
    });

     

    posted on 2007-08-07 20:19 菠蘿 閱讀(648) 評論(0)  編輯  收藏 所屬分類: EXT

    主站蜘蛛池模板: 久久精品免费观看国产| 亚洲国产综合久久天堂| 日韩高清免费观看| 亚洲精品少妇30p| 中国china体内裑精亚洲日本| 美女被爆羞羞网站免费| 99久久精品国产免费| 免费jlzzjlzz在线播放视频| 777亚洲精品乱码久久久久久| 人人公开免费超级碰碰碰视频| 在线视频免费观看爽爽爽| 亚洲综合在线另类色区奇米 | 国产偷国产偷亚洲高清日韩| 国产成+人+综合+亚洲专| 免费无码av片在线观看| 国产免费爽爽视频免费可以看| 亚洲女人影院想要爱| 男人进去女人爽免费视频国产| 久久久亚洲精品国产| 国产乱子伦精品免费视频| 拔擦拔擦8x华人免费久久| 国产天堂亚洲精品| 国产香蕉九九久久精品免费| 久久久久久亚洲Av无码精品专口 | 亚洲日本VA中文字幕久久道具| 一区二区在线免费观看| 亚洲午夜无码久久久久| 一级做a爰片性色毛片免费网站| 亚洲愉拍99热成人精品热久久| 日本一卡精品视频免费| 亚洲色成人网站WWW永久四虎 | 亚洲阿v天堂在线2017免费| 亚洲kkk4444在线观看| 国产亚洲福利一区二区免费看| 两个人日本免费完整版在线观看1| 亚洲成A人片77777国产| 无码人妻精品中文字幕免费| 亚洲熟妇无码AV| 亚洲午夜国产精品无码老牛影视| 午夜免费1000部| 精品国产成人亚洲午夜福利|