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设计模式 封装和信息隐藏(上)
Jul 24 Javascript
jQuery中toggleClass()方法用法实例
Jan 05 Javascript
使用jquery操作session方法分享
Jan 22 Javascript
JS+CSS实现可以凹陷显示选中单元格的方法
Mar 02 Javascript
JavaScript实现自动对页面上敏感词进行屏蔽的方法
Jul 27 Javascript
JS+CSS实现大气清新的滑动菜单效果代码
Oct 22 Javascript
基于jQuery实现的美观星级评论打分组件代码
Oct 30 Javascript
Jquery promise实现一张一张加载图片
Nov 13 Javascript
js中的触发事件对象event.srcElement与event.target详解
Mar 15 Javascript
使用vue + less 实现简单换肤功能的示例
Feb 21 Javascript
uni app仿微信顶部导航条功能
Sep 17 Javascript
Vue vee-validate插件的简单使用
Jun 22 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基础知识:控制结构
2006/12/13 PHP
PHP无限分类的类
2007/01/02 PHP
php中用socket模拟http中post或者get提交数据的示例代码
2013/08/08 PHP
eaglephp使用微信api接口开发微信框架
2014/01/09 PHP
带你了解PHP7 性能翻倍的关键
2015/11/19 PHP
CodeIgniter生成静态页的方法
2016/05/17 PHP
php指定长度分割字符串str_split函数用法示例
2017/01/30 PHP
PHP 的Opcache加速的使用方法
2017/12/29 PHP
一个用js实现的页内搜索代码
2007/05/23 Javascript
jQuery选择器的工作原理和优化分析
2011/07/25 Javascript
由Javascript实现的页面日历
2011/11/04 Javascript
javascript 进阶篇2 CSS XML学习
2012/03/14 Javascript
JavaScript中检查对象property的存在性方法介绍
2014/12/30 Javascript
Vue制作Todo List网页
2017/04/26 Javascript
vue.js开发环境搭建教程
2017/05/04 Javascript
Angular 通过注入 $location 获取与修改当前页面URL的实例
2017/05/31 Javascript
vue中关闭eslint的方法分析
2018/08/04 Javascript
vueJs实现DOM加载完之后自动下拉到底部的实例代码
2018/08/31 Javascript
总结4个方面优化Vue项目
2019/02/11 Javascript
jQuery AJAX与jQuery事件的分析讲解
2019/02/18 jQuery
Vue通过for循环随机生成不同的颜色或随机数的实例
2019/11/09 Javascript
从0到1学习JavaScript编写贪吃蛇游戏
2020/07/28 Javascript
vue中watch的用法汇总
2020/12/28 Vue.js
[01:18:21]EG vs TNC Supermajor小组赛B组败者组第一轮 BO3 第一场 6.2
2018/06/03 DOTA
python利用hook技术破解https的实例代码
2013/03/25 Python
Python中的yield浅析
2014/06/16 Python
详解Python3之数据指纹MD5校验与对比
2019/06/11 Python
Python HTTP下载文件并显示下载进度条功能的实现
2020/04/02 Python
深入解析HTML5中的Blob对象的使用
2015/09/08 HTML / CSS
用canvas显示验证码的实现
2020/04/10 HTML / CSS
MAC Cosmetics官方网站:魅可专业艺术彩妆
2019/04/10 全球购物
加拿大的标志性百货公司:Hudson’s Bay(哈得逊湾)
2019/09/03 全球购物
你所在的项目是如何确定版本号的
2015/12/28 面试题
企业总经理助理岗位职责
2014/09/12 职场文书
十大动画制作软件,Adobe产品上榜两款,第一是行业标准软件
2022/03/18 杂记
Java8利用Stream对列表进行去除重复的方法详解
2022/04/14 Java/Android