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 相关文章推荐
innerHTML与jquery里的html()区别介绍
Oct 12 Javascript
『jQuery』.html(),.text()和.val()的概述及使用
Apr 22 Javascript
javascript实现数组中的内容随机输出
Aug 11 Javascript
微信小程序 实战程序简易新闻的制作
Jan 09 Javascript
JS库 Highlightjs 添加代码行号的实现代码
Sep 13 Javascript
vue watch自动检测数据变化实时渲染的方法
Jan 16 Javascript
vue2.0 better-scroll 实现移动端滑动的示例代码
Jan 25 Javascript
浅谈VUE-CLI脚手架热更新太慢的原因和解决方法
Sep 28 Javascript
浏览器事件循环与vue nextTicket的实现
Apr 16 Javascript
微信小程序实现弹出菜单动画
Jun 21 Javascript
解决使用layui对select append元素无效或者未及时更新的问题
Sep 18 Javascript
浅谈v-for 和 v-if 并用时筛选条件方法
Nov 07 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
世界第一个无线广播电台 KDKA
2021/03/01 无线电
发一个php简单的伪原创程序,配合商城采集用的
2010/10/12 PHP
PHP curl 并发最佳实践代码分享
2012/09/05 PHP
php+ajax实现图片文件上传功能实例
2014/06/17 PHP
将CMYK颜色值和RGB颜色相互转换的PHP代码
2014/07/28 PHP
php+Mysqli利用事务处理转账问题实例
2015/02/11 PHP
php从字符串创建函数的方法
2015/03/16 PHP
PHP快速生成各种信息提示框的方法
2016/02/03 PHP
thinkPHP简单导入和使用阿里云OSSsdk的方法
2017/03/15 PHP
PHP设计模式之装饰器模式实例详解
2018/02/07 PHP
PHP操作MongoDB实现增删改查功能【附php7操作MongoDB方法】
2018/04/24 PHP
通过js动态操作table(新增,删除相关列信息)
2012/05/23 Javascript
extjs tabpanel限制选项卡数量实现思路及代码
2013/04/02 Javascript
JavaScript Math.ceil() 函数使用介绍
2013/12/11 Javascript
使用Raygun对Node.js应用进行错误处理的方法
2015/06/23 Javascript
vue.js入门教程之绑定class和style样式
2016/09/02 Javascript
Bootstrap页面缩小变形的快速解决办法
2017/02/03 Javascript
JS实现十字坐标跟随鼠标效果
2017/12/25 Javascript
详解vue 数组和对象渲染问题
2018/09/21 Javascript
微信小程序实现上传word、txt、Excel、PPT等文件功能
2019/05/23 Javascript
jquery实现下载图片功能
2019/07/18 jQuery
小程序最新获取用户昵称和头像的方法总结
2019/09/23 Javascript
JavaScript编写开发动态时钟
2020/07/29 Javascript
利用Python的装饰器解决Bottle框架中用户验证问题
2015/04/24 Python
利用Python的sympy包求解一元三次方程示例
2019/11/22 Python
修改Pandas的行或列的名字(重命名)
2019/12/18 Python
Django实现celery定时任务过程解析
2020/04/21 Python
Pycharm中安装wordcloud等库失败问题及终端通过pip安装的Python库如何添加到Pycharm解释器中(推荐)
2020/05/10 Python
Python字符串的15个基本操作(小结)
2021/02/03 Python
党员公开承诺书和承诺事项
2014/03/25 职场文书
结婚保证书范文
2014/04/29 职场文书
2014报到证办理个人委托书
2014/10/08 职场文书
七一晚会主持词
2015/06/29 职场文书
WordPress多语言翻译插件 - WPML使用教程
2021/04/01 PHP
JavaScript高级程序设计之变量与作用域
2021/11/17 Javascript
VUE递归树形实现多级列表
2022/07/15 Vue.js