ExtJs 3.1 XmlTreeLoader Example Error
前言
關(guān)鍵字:ExtJs 3.1 XmlTreeLoader Example Error,XmlTreeLoader 錯(cuò)誤,TreePanel Error
ExtJs 3.1的XmlTreeLoader例子折騰了我近一個(gè)下午加晚上,官方的例子沒有問題,可以加載xml的數(shù)據(jù),本地IIS死活不行,也不報(bào)錯(cuò),直接查看官方的代碼也是一模一樣的,今早意外給讓我搜到了,不是在官方,而是在貌似一個(gè)韓國的博客里面找到的,致敬一下,本文且做其簡單中文"譯"本。
原文
http://javarush.com/entry/ExtJS-XmlTreeLoader-Error
正文
1. 代碼位置:Ext3.1\examples\tree\xml-tree-loader.js
2. 注意標(biāo)紅新增代碼",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
}]
});
});
結(jié)束語
不要放棄和接受一次失敗的搜索,不斷的嘗試改變搜索關(guān)鍵字,哪怕是用詞霸翻成英文也得努力去試試,看不懂不要緊,看懂代碼就行,代碼無國界: )
相關(guān)文章
入門基礎(chǔ)學(xué)習(xí) ExtJS筆記(一)
這段時(shí)間手中項(xiàng)目已經(jīng)完成,空閑時(shí)間較多。開始了學(xué)習(xí)ExtJs之旅。2010-11-11
常用Extjs工具:Extjs.util.Format使用方法
常用Extjs工具:Extjs.util.Format使用方法,需要的朋友可以參考下2012-03-03
extjs tabpanel限制選項(xiàng)卡數(shù)量實(shí)現(xiàn)思路及代碼
使用的是用變量存儲 id 加載新的選卡時(shí) 交換 id ,從而限制了打開的選項(xiàng)卡數(shù)量,如果不是一定要這個(gè)效果,建議不要頻繁的關(guān)閉和創(chuàng)建tabpanel,感興趣的朋友可以參考下哈2013-04-04
學(xué)習(xí)ExtJS(一) 之基礎(chǔ)前提
學(xué)習(xí)ExtJS前提條件,大家要想學(xué)習(xí),需要一些基礎(chǔ)知識。2009-10-10
EXTjs4.0的store的findRecord的BUG演示代碼
EXTjs4.0 的store的findRecord的BUG:當(dāng)判斷ID=1的時(shí)候,遇到1開頭的ID的時(shí)候,這個(gè)時(shí)候就判斷出問題了,有類似問題的朋友可以了解下哈2013-06-06
Extjs grid添加一個(gè)圖片狀態(tài)或者按鈕的方法
extjs的grid中我們經(jīng)常需要添加一個(gè)圖片狀態(tài)或者按鈕,下面將自己用過的一些方法與大家分享下2014-04-04
ExtJs Excel導(dǎo)出并下載IIS服務(wù)器端遇到的問題
進(jìn)項(xiàng)目一個(gè)多月不到。熟悉了這個(gè)二次開發(fā)的項(xiàng)目因?yàn)榍懊孢z留下來的問題比較嚴(yán)重報(bào)表的導(dǎo)出和圖表以及打印功能都沒有實(shí)現(xiàn),所以這兩天工作量比較大。2011-09-09
Extjs改變樹節(jié)點(diǎn)的勾選狀態(tài)點(diǎn)擊按鈕將復(fù)選框去掉
需要一個(gè)功能點(diǎn)擊一個(gè)按鈕后將樹節(jié)點(diǎn)前的復(fù)選框去掉,變成沒有選擇的狀態(tài),百度一下發(fā)現(xiàn)個(gè)不錯(cuò)的方法,需要的朋友可以參考下2013-11-11

