首先导入Ext.ux.tree.XmlTreeLoader.js
/*!
* Ext JS Library 3.2.0
* Copyright(c) 2006-2010 Ext JS, Inc.
* licensing@extjs.com
* http://www.extjs.com/license
*/
Ext.ns('Ext.ux.tree');
/**
* @class Ext.ux.tree.XmlTreeLoader
* @extends Ext.tree.TreeLoader
*
* @constructor
* Creates a new XmlTreeloader.
* @param {Object} config A config object containing config properties.
*/
Ext.ux.tree.XmlTreeLoader = Ext.extend(Ext.tree.TreeLoader, {
/**
* @property XML_NODE_ELEMENT
* XML element node (value 1, read-only)
* @type Number
*/
XML_NODE_ELEMENT : 1,
/**
* @property XML_NODE_TEXT
* XML text node (value 3, read-only)
* @type Number
*/
XML_NODE_TEXT : 3,
// private override
processResponse : function(response, node, callback){
var xmlData = response.responseXML;
var root = xmlData.documentElement || xmlData;
try{
node.beginUpdate();
node.appendChild(this.parseXml(root));
node.endUpdate();
if(typeof callback == "function"){
callback(this, node);
}
}catch(e){
this.handleFailure(response);
}
},
// private
parseXml : function(node) {
var nodes = [];
Ext.each(node.childNodes, function(n){
if(n.nodeType == this.XML_NODE_ELEMENT){
var treeNode = this.createNode(n);
if(n.childNodes.length > 0){
var child = this.parseXml(n);
if(typeof child == 'string'){
treeNode.attributes.innerText = child;
treeNode.text = child;
}else{
treeNode.appendChild(child);
}
}
nodes.push(treeNode);
}
else if(n.nodeType == this.XML_NODE_TEXT){
var text = n.nodeValue.trim();
if(text.length > 0){
return nodes = text;
}
}
}, this);
return nodes;
},
// private override
createNode : function(node){
var attr = {
tagName: node.tagName
};
Ext.each(node.attributes, function(a){
attr[a.nodeName] = a.nodeValue;
});
this.processAttributes(attr);
return Ext.ux.tree.XmlTreeLoader.superclass.createNode.call(this, attr);
},
/*
* Template method intended to be overridden by subclasses that need to provide
* custom attribute processing prior to the creation of each TreeNode. This method
* will be passed a config object containing existing TreeNode attribute name/value
* pairs which can be modified as needed directly (no need to return the object).
*/
processAttributes: Ext.emptyFn
});
//backwards compat
Ext.ux.XmlTreeLoader = Ext.ux.tree.XmlTreeLoader;
然后添加针对XML文件格式的子类:
Ext.app.TestLoader = Ext.extend(Ext.ux.tree.XmlTreeLoader, {
processAttributes : function(attr){
if(attr.tagName=="category"){
attr.text = attr.name;
//attr.iconCls = '';
attr.loaded = true;
attr.expanded = false;
if(attr.isValid != "true"){
attr.hidden = true;
}
}
else if(attr.tagName=="select"){
//attr.iconCls = '';
attr.leaf = true;
}
}
});
Tree中数据的载入:
var tree = new Ext.tree.TreePanel({
renderTo: 'item',
width: 500,
height: 500,
autoScroll:true,
rootVisible: true,
root: new Ext.tree.AsyncTreeNode({
text: 'Root,
expanded: true
}),
loader: new Ext.app.TestLoader({
dataUrl:'data.xml'
})
});
A TreeLoader that can convert an XML document into a hierarchy of {@link Ext.tree.TreeNode}s.
* Any text value included as a text node in the XML will be added to the parent node as an attribute
* called innerText. Also, the tag name of each XML node will be added to the tree node as
* an attribute called tagName.
*
By default, this class expects that your source XML will provide the necessary attributes on each
* node as expected by the {@link Ext.tree.TreePanel} to display and load properly. However, you can
* provide your own custom processing of node attributes by overriding the {@link #processNode} method
* and modifying the attributes as needed before they are used to create the associated TreeNode.
分享到:
相关推荐
ExtJs Tree
最近在学习extjs tree,有两个不错的例子,希望对需要的朋友有所帮助!
extjs tree 异步加载树型完整的一个web工程,自已已经试过,可用。
Extjs的tree Extjs的tree Extjs的tree Extjs的tree Extjs的tree
extjs tree 学习资料extjs tree 学习资料extjs tree 学习资料extjs tree 学习资料
ExtJs 2.2.1 tree实例,内附mysql数据文件 1. 数据节点一次性加载 2. 节点分为两个类(项目和设备) 3. 右键菜单 4. 节点增、删、改操作 ....... 后台是java struts1。 本例旨在说明extjs的tree操作,后台操作很简陋...
Extjs Tree + JSON + Struts2 例子
Extjs Tree + JSON + Struts2 示例源代码
区别在于,远程脚本调用方式加载树节点信息使用的是WebInvokeTreeLoader,需要通过fn属性来指定用于加载数据的远程方法,并在...而传统的树节点加载器是Ext.tree.TreeLoader,需要指定一个url来获得json数据。
extjs的tree的使用.doc
ExtJs4 Checkbox tree
Ext各种组件的使用实例,Extjs tree+grid+form+panel 使用实例
access 数据库,可增加 删除树节点!!
在网上下载别人的代码,改进加上CHECKBOX ,但是批量删除做不出来,希望高手完成并分享。
分享一个ExtJs Tree, 完整的带有复选框的树形结构
利用extjs框架实现的后台经典显示, tree框架,动态加载。
extjs tree + json+struts2示例源代码extjs tree + json+struts2示例源代码
Extjs Tree + JSON + Struts2 开发war包
ExtJS Tree教程及例子代码 eclipse项目导入后打开index就有各类的例子 还有个excel教程
java写的Extjs异步树形控件示例,可直接部署