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è)韓國(guó)的博客里面找到的,致敬一下,本文且做其簡(jiǎn)單中文"譯"本。
原文
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ó)界: )
相關(guān)文章
Ext中下拉列表ComboBox組件store數(shù)據(jù)格式用法介紹
本文為大家詳細(xì)介紹下Ext中下拉列表ComboBox組件store數(shù)據(jù)格式的基本用法,感興趣的朋友可以參考下哈,希望對(duì)大家有所幫助2013-07-07extjs 3.31 TreeGrid實(shí)現(xiàn)靜態(tài)頁面加載json到TreeGrid里面
extjs 3.31 TreeGrid 我的小改動(dòng),實(shí)現(xiàn)靜態(tài)頁面加載json到TreeGrid里面2013-04-04Extjs NumberField后面加單位實(shí)現(xiàn)思路
本文為大家介紹下在NumberField后面加單位,具體實(shí)現(xiàn)如下,感興趣的朋友可以參考下2013-07-07ExtJS Ext.MessageBox.alert()彈出對(duì)話框詳解
Ext.MessageBox是一個(gè)工具類,他繼承自O(shè)biect對(duì)象,用來生成各種風(fēng)格的信息提示對(duì)話框,Ext.Msg是該類的別名,使用Ext.MessageBox和用Ext.Msg效果是一樣的,而后者提供了更簡(jiǎn)單的方式。2010-04-04Extjs Ext.MessageBox.confirm 確認(rèn)對(duì)話框詳解
顯示一個(gè)確認(rèn)對(duì)話框,用來代替JavaScript標(biāo)準(zhǔn)的confirm()方法,具有兩個(gè)按鈕“是”和“否”如果為其提供一個(gè)回調(diào)函數(shù),則該函數(shù)將在單擊按鈕后被調(diào)用(包括右上角的推出按鈕),所單擊按鈕的id將被作為唯一的參數(shù)傳遞到回調(diào)函數(shù)中。2010-04-04ExtJS 2.0實(shí)用簡(jiǎn)明教程 之ExtJS版的Hello
下面我們寫一個(gè)最簡(jiǎn)單的ExtJS應(yīng)用,在hello.html文件中輸入下面的代碼2009-04-04