2017-01-04 17 views
1

我正在創建Extjs版本3.2.1中的樹面板,我有代碼可以從我的服務器中可用的xml文檔(tree.xml)構造樹這工作正常。從保存爲全局常量的xmlDocument中創建Extjs樹面板

但我在新的形勢下,我的反應是保存在全局常變量

從Ext.Ajax的請求,我得到了響應,並保存像下面

global_const = response.responseXML; 

我的問題是,我該怎麼將global_const傳遞給treeloader?

任何幫助和建議是感激

回答

1

我使用JSON而不是XML

var Tree = Ext.tree; 

    var tree = new Tree.TreePanel('tree', { 
     animate:true, 
     enableDD:false, 
    loader: new Tree.TreeLoader(), // Note: no dataurl, register a TreeLoader to make use of createNode() 
    lines: true, 
    selModel: new Ext.tree.MultiSelectionModel(), 
     containerScroll: false 
    }); 


    // json data describing the tree 
    var json = 
[ 
{"text" : "Audi", "id" : 100, "leaf" : false, "cls" : "folder", "children" : [ 
    {"text" : "A3", "id" : 1000, "leaf" : false, "cls" : "folder", "children" : 
     [ {"text" : "Fuel Economy", "id" : "100000", "leaf" : true, "cls" : "file"}, 
      {"text" : "Invoice", "id" : "100001", "leaf" : true, "cls" : "file"}, 
      {"text" : "MSRP", "id" : "100002", "leaf" : true, "cls" : "file"}, 
      {"text" : "Options", "id" : "100003", "leaf" : true, "cls" : "file"}, 
      {"text" : "Specifications", "id" : "100004", "leaf" : true, "cls" : "file"} 
     ] 
    }, 
    {"text" : "TT", "id" : 1000, "leaf" : false, "cls" : "folder", "children" : 
     [ {"text" : "Fuel Economy", "id" : "100000", "leaf" : true, "cls" : "file"}, 
      {"text" : "Invoice", "id" : "100001", "leaf" : true, "cls" : "file"}, 
      {"text" : "MSRP", "id" : "100002", "leaf" : true, "cls" : "file"}, 
      {"text" : "Options", "id" : "100003", "leaf" : true, "cls" : "file"}, 
      {"text" : "Specifications", "id" : "100004", "leaf" : true, "cls" : "file"} 
     ] 
    }] 
}, 
{"text" : "Cadillac", "id" : 300, "leaf" : false, "cls" : "folder", "children" : [ 
    {"text" : "CTS", "id" : 1000, "leaf" : false, "cls" : "folder", "children" : 
     [ {"text" : "Fuel Economy", "id" : "100000", "leaf" : true, "cls" : "file"}, 
      {"text" : "Invoice", "id" : "100001", "leaf" : true, "cls" : "file"}, 
      {"text" : "MSRP", "id" : "100002", "leaf" : true, "cls" : "file"}, 
      {"text" : "Options", "id" : "100003", "leaf" : true, "cls" : "file"}, 
      {"text" : "Specifications", "id" : "100004", "leaf" : true, "cls" : "file"} 
     ] 
    }, 
    {"text" : "CTS-V", "id" : 1000, "leaf" : false, "cls" : "folder", "children" : 
     [ {"text" : "Fuel Economy", "id" : "100000", "leaf" : true, "cls" : "file"}, 
      {"text" : "Invoice", "id" : "100001", "leaf" : true, "cls" : "file"}, 
      {"text" : "MSRP", "id" : "100002", "leaf" : true, "cls" : "file"}, 
      {"text" : "Options", "id" : "100003", "leaf" : true, "cls" : "file"}, 
      {"text" : "Specifications", "id" : "100004", "leaf" : true, "cls" : "file"} 
     ] 
    }] 
} 

]; 

    // set the root node 
    var root = new Tree.AsyncTreeNode({ 
     text: 'Autos', 
     draggable:false, 
     id:'source', 
     children: json 
    }); 

    tree.setRootNode(root); 

    tree.render(); 
    root.expand();