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实现仿Windows关机效果
Mar 10 Javascript
js 表单验证方法(实用)
Apr 28 Javascript
js操作iframe兼容各种主流浏览器示例代码
Jul 22 Javascript
JavaScript中连接操作Oracle数据库实例
Apr 02 Javascript
ExtJs动态生成treepanel的Json格式
Jul 19 Javascript
JavaScript实现LI列表数据绑定的方法
Aug 04 Javascript
javascript正则表达式定义(语法)总结
Jan 08 Javascript
使用Ajax和Jquery配合数据库实现下拉框的二级联动的示例
Jan 25 jQuery
Vue.js进阶知识点总结
Apr 01 Javascript
Vue slot用法(小结)
Oct 22 Javascript
微信小程序开发之map地图组件定位并手动修改位置偏差
Aug 17 Javascript
微信小程序用户授权最佳实践指南
May 08 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
BBS(php &amp; mysql)完整版(六)
2006/10/09 PHP
php foreach 使用&amp;(与运算符)引用赋值要注意的问题
2010/02/16 PHP
PHP+MySQL统计该库中每个表的记录数并按递减顺序排列的方法
2016/02/15 PHP
phpmailer简单发送邮件的方法(附phpmailer源码下载)
2016/06/13 PHP
php实现获取农历(阴历)、节日、节气的类与用法示例
2017/11/20 PHP
PHP中SESSION过期设置
2021/03/09 PHP
javascript通过class来获取元素实现代码
2013/02/20 Javascript
JavaScript中使用document.write向页面输出内容实例
2014/10/16 Javascript
js控制鼠标事件移动及移出效果显示
2014/10/19 Javascript
Bootstrap~多级导航(级联导航)的实现效果【附代码】
2016/03/08 Javascript
EasyUI的doCellTip实现鼠标放到单元格上提示单元格内容
2016/08/24 Javascript
jQuery包裹节点用法完整示例
2016/09/13 Javascript
three.js快速入门【推荐】
2017/01/21 Javascript
NodeJS处理Express中异步错误
2017/03/26 NodeJs
Vue2.0实现购物车功能
2017/06/05 Javascript
seajs实现强制刷新本地缓存的方法分析
2017/10/16 Javascript
nodejs前端模板引擎swig入门详解
2018/05/15 NodeJs
浅析vue.js数组的变异方法
2018/06/30 Javascript
微信小程序修改swiper默认指示器样式的实例代码
2018/07/18 Javascript
vue-router路由懒加载的实现(解决vue项目首次加载慢)
2018/08/28 Javascript
在Vue methods中调用filters里的过滤器实例
2018/08/30 Javascript
vue axios 简单封装以及思考
2018/10/09 Javascript
Vue.js的复用组件开发流程完整记录
2018/11/29 Javascript
利用es6 new.target来对模拟抽象类的方法
2019/05/10 Javascript
layer关闭弹出窗口触发表单提交问题的处理方法
2019/09/25 Javascript
PyQt5 实现给窗口设置背景图片的方法
2019/06/13 Python
python GUI库图形界面开发之PyQt5打开保存对话框QFileDialog详细使用方法与实例
2020/02/27 Python
python实现录屏功能(亲测好用)
2020/03/02 Python
Django添加bootstrap框架时无法加载静态文件的解决方式
2020/03/27 Python
CSS3 中filter(滤镜)属性使用详解
2020/04/07 HTML / CSS
常见的软件开发流程有哪些
2015/11/14 面试题
物理系毕业生自荐信
2013/11/01 职场文书
高中语文教学反思范文
2016/02/16 职场文书
2016年优秀共产党员先进事迹材料
2016/02/29 职场文书
go mod 安装依赖 unkown revision问题的解决方案
2021/05/06 Golang
Java服务调用RestTemplate与HttpClient的使用详解
2022/06/21 Java/Android