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 相关文章推荐
执行iframe中的javascript方法
Oct 07 Javascript
JSQL 基于客户端的成绩统计实现方法
May 05 Javascript
JS遮罩层效果 兼容ie firefox jQuery遮罩层
Jul 26 Javascript
jQuery过滤选择器详解
Jan 13 Javascript
JavaScript获取网页中第一个链接ID的方法
Apr 03 Javascript
jquery实现Ctrl+Enter提交表单的方法
Jul 21 Javascript
AngularJS入门教程引导程序
Aug 18 Javascript
js显示动态时间的方法详解
Aug 20 Javascript
JavaScript String(字符串)对象的简单实例(推荐)
Aug 31 Javascript
浅谈javascript:两种注释,声明变量,定义函数
Sep 29 Javascript
基于JS实现的随机数字抽签实例
Dec 08 Javascript
JavaScript适配器模式详解
Oct 19 Javascript
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目录操作实例代码
2014/02/21 PHP
提交表单时执行func方法实现代码
2013/03/17 Javascript
jquery struts 验证唯一标识(公用方法)
2013/03/27 Javascript
关于js数组去重的问题小结
2014/01/24 Javascript
javascript实现iframe框架延时加载的方法
2014/10/30 Javascript
PHP中使用微秒计算脚本执行时间例子
2014/11/19 Javascript
js实现键盘控制DIV移动的方法
2015/01/10 Javascript
微信js-sdk分享功能接口常用逻辑封装示例
2016/10/13 Javascript
JS实现的倒计时恢复按钮点击功能【可用于协议阅读倒计时】
2018/04/19 Javascript
JavaScript 正则命名分组【推荐】
2018/06/07 Javascript
微信小程序image图片加载完成监听
2019/08/31 Javascript
解决layer.confirm快速点击会重复触发事件的问题
2019/09/23 Javascript
纯js+css实现在线时钟
2020/08/18 Javascript
JS canvas实现画板和签字板功能
2021/02/23 Javascript
2款Python内存检测工具介绍和使用方法
2014/06/01 Python
python在windows下实现备份程序实例
2014/07/04 Python
深入学习Python中的上下文管理器与else块
2017/08/27 Python
Python计算库numpy进行方差/标准方差/样本标准方差/协方差的计算
2018/12/28 Python
tensorflow中tf.slice和tf.gather切片函数的使用
2020/01/19 Python
关于Django Models CharField 参数说明
2020/03/31 Python
Numpy一维线性插值函数的用法
2020/04/22 Python
python中strip(),lstrip(),rstrip()函数的使用讲解
2020/11/17 Python
Pandas数据分析的一些常用小技巧
2021/02/07 Python
VSCode 自定义html5模板的实现
2019/12/05 HTML / CSS
施华洛世奇德国官网:SWAROVSKI德国
2017/02/01 全球购物
Net-A-Porter美国官网:全球时尚奢侈品名站
2017/02/11 全球购物
ASOS英国官网:英国在线时装和化妆品零售商
2017/05/19 全球购物
声明struct x1 { . . . }; 和typedef struct { . . . }x2;有什么不同
2012/06/02 面试题
什么是TCP/IP
2014/07/27 面试题
Java面试题汇总
2015/12/06 面试题
给校长的一封建议书
2014/03/12 职场文书
实习指导老师评语
2014/04/26 职场文书
令人印象深刻的自荐信
2014/05/25 职场文书
高中校园广播稿3篇
2014/09/29 职场文书
创业计划书之冷饮店
2019/09/27 职场文书
mysql数据库隔离级别详解
2022/06/16 MySQL