ExtJs 3.1 XmlTreeLoader Example Error


Posted in Javascript onFebruary 09, 2010

前言

关键字:ExtJs 3.1 XmlTreeLoader Example Error,XmlTreeLoader 错误,TreePanel Error

ExtJs 3.1的XmlTreeLoader例子折腾了我近一个下午加晚上,官方的例子没有问题,可以加载xml的数据,本地IIS死活不行,也不报错,直接查看官方的代码也是一模一样的,今早意外给让我搜到了,不是在官方,而是在貌似一个韩国的博客里面找到的,致敬一下,本文且做其简单中文"译"本。

原文

http://javarush.com/entry/ExtJS-XmlTreeLoader-Error 

正文

1.

代码位置:Ext3.1\examples\tree\xml-tree-loader.js

2.

注意标红新增代码",requestMethod: 'GET'"!!

/*! 
* Ext JS Library 3.1.0 
* Copyright(c) 2006-2009 Ext JS, LLC 
* licensing@extjs.com 
* http://www.extjs.com/license 
*/ // 
// Extend the XmlTreeLoader to set some custom TreeNode attributes specific to our application: 
// 
Ext.app.BookLoader = Ext.extend(Ext.ux.tree.XmlTreeLoader, { 
processAttributes : function(attr){ 
if(attr.first){ // is it an author node? 
// Set the node text that will show in the tree since our raw data does not include a text attribute: 
attr.text = attr.first + ' ' + attr.last; 
// Author icon, using the gender flag to choose a specific icon: 
attr.iconCls = 'author-' + attr.gender; 
// Override these values for our folder nodes because we are loading all data at once. If we were 
// loading each node asynchronously (the default) we would not want to do this: 
attr.loaded = true; 
attr.expanded = true; 
} 
else if(attr.title){ // is it a book node? 
// Set the node text that will show in the tree since our raw data does not include a text attribute: 
attr.text = attr.title + ' (' + attr.published + ')'; 
// Book icon: 
attr.iconCls = 'book'; 
// Tell the tree this is a leaf node. This could also be passed as an attribute in the original XML, 
// but this example demonstrates that you can control this even when you cannot dictate the format of 
// the incoming source XML: 
attr.leaf = true; 
} 
} 
}); 
Ext.onReady(function(){ 
var detailsText = '<i>Select a book to see more information...</i>'; 
var tpl = new Ext.Template( 
'<h2 class="title">{title}</h2>', 
'<p><b>Published</b>: {published}</p>', 
'<p><b>Synopsis</b>: {innerText}</p>', 
'<p><a href="{url}" target="_blank">Purchase from Amazon</a></p>' 
); 
tpl.compile(); 
new Ext.Panel({ 
title: 'Reading List', 
renderTo: 'tree', 
layout: 'border', 
width: 500, 
height: 500, 
items: [{ 
xtype: 'treepanel', 
id: 'tree-panel', 
region: 'center', 
margins: '2 2 0 2', 
autoScroll: true, 
rootVisible: false, 
root: new Ext.tree.AsyncTreeNode(), 
// Our custom TreeLoader: 
loader: new Ext.app.BookLoader({ 
dataUrl:'xml-tree-data.xml' 
,requestMethod: 'GET' 
}), 
listeners: { 
'render': function(tp){ 
tp.getSelectionModel().on('selectionchange', function(tree, node){ 
var el = Ext.getCmp('details-panel').body; 
if(node && node.leaf){ 
tpl.overwrite(el, node.attributes); 
}else{ 
el.update(detailsText); 
} 
}) 
} 
} 
},{ 
region: 'south', 
title: 'Book Details', 
id: 'details-panel', 
autoScroll: true, 
collapsible: true, 
split: true, 
margins: '0 2 2 2', 
cmargins: '2 2 2 2', 
height: 220, 
html: detailsText 
}] 
}); 
});

结束语

不要放弃和接受一次失败的搜索,不断的尝试改变搜索关键字,哪怕是用词霸翻成英文也得努力去试试,看不懂不要紧,看懂代码就行,代码无国界: )

Javascript 相关文章推荐
javascript Split方法,indexOf方法、lastIndexOf 方法和substring 方法
Mar 21 Javascript
jQeury淡入淡出需要注意的问题
Sep 08 Javascript
深入浅出讲解ES6的解构
Aug 03 Javascript
JS正则表达式修饰符中multiline(/m)用法分析
Dec 27 Javascript
JavaScript数据结构之二叉树的查找算法示例
Apr 13 Javascript
JavaScript数组的5种迭代方法
Sep 29 Javascript
AngularJS监听ng-repeat渲染完成的两种方法
Jan 16 Javascript
vue click.stop阻止点击事件继续传播的方法
Sep 04 Javascript
electron制作仿制qq聊天界面的示例代码
Nov 26 Javascript
js 根据对象数组中的属性进行排序实现代码
Sep 12 Javascript
angular组件间通讯的实现方法示例
May 07 Javascript
Vue深入理解插槽slot的使用
Aug 05 Vue.js
Javascript 获取链接(url)参数的方法[正则与截取字符串]
Feb 09 #Javascript
一个XML格式数据转换为图表的例子
Feb 09 #Javascript
javascript 解析url的search方法
Feb 09 #Javascript
toString()一个会自动调用的方法
Feb 08 #Javascript
jQuery AJAX回调函数this指向问题
Feb 08 #Javascript
JavaScript Event学习第九章 鼠标事件
Feb 08 #Javascript
JavaScript 类似flash效果的立体图片浏览器
Feb 08 #Javascript
You might like
php使用function_exists判断函数可用的方法
2014/11/19 PHP
PHP中使用Imagick实现各种图片效果实例
2015/01/21 PHP
阻止JavaScript事件冒泡传递(cancelBubble 、stopPropagation)
2007/05/08 Javascript
js 鼠标点击事件及其它捕获
2009/06/04 Javascript
jQuery 下拉列表 二级联动插件分享
2012/03/29 Javascript
dtree 网页树状菜单及传递对象集合到js内,动态生成节点
2012/04/14 Javascript
JS截取字符串常用方法整理及使用示例
2013/10/18 Javascript
深入学习JavaScript中的Rest参数和参数默认值
2015/07/28 Javascript
举例讲解Node.js中的Writable对象
2015/07/29 Javascript
js实现三张图(文)片一起切换的banner焦点图
2015/08/25 Javascript
ajax在兼容模式下失效的快速解决方法
2016/03/22 Javascript
AngularJS入门教程之Select(选择框)详解
2016/07/27 Javascript
Node.js 异步异常的处理与domain模块解析
2017/05/10 Javascript
Vue项目中使用jquery的简单方法
2019/05/16 jQuery
JavaScript实现雪花飘落效果
2020/12/27 Javascript
[06:09]辉夜杯主赛事开幕式
2015/12/25 DOTA
用Python从零实现贝叶斯分类器的机器学习的教程
2015/03/31 Python
python中getaddrinfo()基本用法实例分析
2015/06/28 Python
Python3 操作符重载方法示例
2017/11/23 Python
pandas数值计算与排序方法
2018/04/12 Python
python 实现提取某个索引中某个时间段的数据方法
2019/02/01 Python
python FTP批量下载/删除/上传实例
2019/12/22 Python
Python with标签使用方法解析
2020/01/17 Python
如何使用Python处理HDF格式数据及可视化问题
2020/06/24 Python
美国最大的珠宝首饰网上商城:Jewelry.com
2016/07/22 全球购物
中学实习教师自我鉴定
2013/12/12 职场文书
四年大学生活的自我评价范文
2014/02/07 职场文书
团日活动总结报告
2014/06/25 职场文书
会计试用期自我评价怎么写
2014/09/18 职场文书
户外活动总结
2015/02/04 职场文书
2015世界地球日活动总结
2015/02/09 职场文书
有关浪费资源的建议书
2015/09/14 职场文书
2016年国陪研修感言
2015/11/18 职场文书
MySQL之DML语言
2021/04/05 MySQL
mysql优化之query_cache_limit参数说明
2021/07/01 MySQL
vue选项卡切换的实现案例
2022/04/11 Vue.js