3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js">
10 // Extend the XmlTreeLoader to set some custom TreeNode attributes specific to our application:
12 Ext.app.BookLoader = Ext.extend(Ext.ux.tree.XmlTreeLoader, {
13 processAttributes : function(attr){
14 if(attr.first){ // is it an author node?
16 // Set the node text that will show in the tree since our raw data does not include a text attribute:
17 attr.text = attr.first + ' ' + attr.last;
19 // Author icon, using the gender flag to choose a specific icon:
20 attr.iconCls = 'author-' + attr.gender;
22 // Override these values for our folder nodes because we are loading all data at once. If we were
23 // loading each node asynchronously (the default) we would not want to do this:
27 else if(attr.title){ // is it a book node?
29 // Set the node text that will show in the tree since our raw data does not include a text attribute:
30 attr.text = attr.title + ' (' + attr.published + ')';
33 attr.iconCls = 'book';
35 // Tell the tree this is a leaf node. This could also be passed as an attribute in the original XML,
36 // but this example demonstrates that you can control this even when you cannot dictate the format of
37 // the incoming source XML:
43 Ext.onReady(function(){
45 var detailsText = '<i>Select a book to see more information...</i>';
47 var tpl = new Ext.Template(
48 '<h2 class="title">{title}</h2>',
49 '<p><b>Published</b>: {published}</p>',
50 '<p><b>Synopsis</b>: {innerText}</p>',
51 '<p><a href="{url}" target="_blank">Purchase from Amazon</a></p>'
56 title: 'Reading List',
68 root: new Ext.tree.AsyncTreeNode(),
70 // Our custom TreeLoader:
71 loader: new Ext.app.BookLoader({
72 dataUrl:'xml-tree-data.xml'
76 'render': function(tp){
77 tp.getSelectionModel().on('selectionchange', function(tree, node){
78 var el = Ext.getCmp('details-panel').body;
79 if(node && node.leaf){
80 tpl.overwrite(el, node.attributes);
82 el.update(detailsText);
89 title: 'Book Details',