从保存在全局常量中的 xmlDocument 创建 Extjs 树面板
Posted
技术标签:
【中文标题】从保存在全局常量中的 xmlDocument 创建 Extjs 树面板【英文标题】:Creating Extjs tree panel from xmlDocument which is saved in global constant 【发布时间】:2017-01-04 05:47:19 【问题描述】:我正在努力在 Extjs 版本 3.2.1 中创建树形面板,我有代码可以从 xml 文档(tree.xml)构建一个树,它在我的服务器中可用,工作正常。
但我处于新情况,我的响应保存在全局常量变量中
从 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();
【讨论】:
以上是关于从保存在全局常量中的 xmlDocument 创建 Extjs 树面板的主要内容,如果未能解决你的问题,请参考以下文章
通过Web.config中的configSections配置自己系统的全局常量