62,046
社区成员
发帖
与我相关
我的任务
分享
/*
* Ext JS Library 2.2.1
* Copyright(c) 2006-2009, Ext JS, LLC.
* licensing@extjs.com
*
* http://extjs.com/license
*/
/**
* @class Ext.ux.XmlTreeLoader
* @extends Ext.tree.TreeLoader
* <p>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 <tt>innerText</tt>. Also, the tag name of each XML node will be added to the tree node as
* an attribute called <tt>tagName</tt>.</p>
* <p>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.</p>
* @constructor
* Creates a new XmlTreeloader.
* @param {Object} config A config object containing config properties.
*/
Ext.ux.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;
} 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.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
});
Ext.app.MyXMLLoader = Ext.extend(Ext.ux.XmlTreeLoader, {
processAttributes: function (attr) {
attr.id = attr.id;
attr.href = attr.url;
attr.text = attr.name;
attr.url = attr.url;
attr.leaf = attr.leaf;
}
});
// left Tree
var menu = new Ext.tree.TreePanel({
title: '系统菜单',
region: "west",
animate: true,
autoScroll: true,
enableTabScroll: true,
collapsible: true,
collapsed: true,
split: true,
rootVisible: true,
lines: true,
width: 220,
minSize: 220,
maxSize: 220,
root: new Ext.tree.AsyncTreeNode({
text: '主菜单',
draggable: false, // 根节点不容许拖动
expanded: false
}),
loader: new Ext.app.MyXMLLoader({
preloadChildren: true,
clearOnLoad: false,
dataUrl: "/manage/LoadTreeXML" //这里访问到action 里 。然后action解析xml。也可以直接写xml url
}),
collapseFirst: false
});
menu.expandAll();
menu.on('click', function (node) {
if (node.leaf == 'true' && typeof node.leaf != 'undefined') {
var tab = tabMain.getComponent(node.id);
if (!tab) {
tab = tabMain.add({
'id': node.id,
'title': node.text,
closable: true, //通过html载入目标页
html: '<iframe scrolling="auto" frameborder="0" width="100%" height="100%" src="' + node.attributes.upost + '"></iframe>'
});
}
tabMain.setActiveTab(tab);
}
});
/// <summary>
/// tree xml数据源
/// </summary>
///
[SessionFilter]
public void LoadTreeXML()
{
StreamReader sr = new StreamReader(Server.MapPath("\\Content\\xml\\xml-tree-data.xml"));
Response.ContentType = "text/xml; charset=utf-8";
string _temp = sr.ReadToEnd();
sr.Close();
Response.Write(_temp);
Response.End();
}
Ext.Ajax.request({
url: 'com/functions.cfc',
success: successMethod,
failure: errorMethod,
headers: {"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"},
params: {method:'setupLife',argument1:arg1,argument2:arg2}
});
<!DOCTYPE html>
<html>
<head>
<script>
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("POST","demo_post2.asp",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("fname=Henry&lname=Ford");
}
</script>
</head>
<body>
<h2>AJAX</h2>
<button type="button" onclick="loadXMLDoc()">Request data</button>
<div id="myDiv"></div>
</body>
</html>
http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_post2