PDA

View Full Version : [CLOSED] [4.1B2] Returning nested XML data for a Tree doesn't work...



mankz
9 Jun 2011, 3:10 AM
...without this patch:

Ext.data.reader.Xml:

extractData: function(root) {
var recordName = this.record;

if (recordName != root.nodeName) {
root = Ext.DomQuery.select('>' + recordName, root);
} else {
root = [root];
}
return this.callParent([root]);
},

evant
14 Jun 2011, 9:31 PM
Can you post a short test case?

mankz
14 Jun 2011, 11:04 PM
Sure, I basically just don't see how nested data should be loaded into a tree. Modify the xml-tree.html example to load from a static XML file instead of the PHP file:



/*

This file is part of Ext JS 4

Copyright (c) 2011 Sencha Inc

Contact: http://www.sencha.com/contact

GNU General Public License Usage
This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.

If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.

*/
Ext.require([
'Ext.tree.*',
'Ext.data.*'
]);

Ext.onReady(function() {

var store = Ext.create('Ext.data.TreeStore', {
proxy: {
type: 'ajax',
url: 'foo.xml',
extraParams: {
isXml: true
},
reader: {
type: 'xml',
root: 'nodes',
record: 'node'
}
},
sorters: [{
property: 'leaf',
direction: 'ASC'
},{
property: 'text',
direction: 'ASC'
}],
root: {
text: 'Ext JS',
id: 'src',
expanded: true
}
});

// create the Tree
var tree = Ext.create('Ext.tree.Panel', {
store: store,
hideHeaders: true,
rootVisible: true,
viewConfig: {
plugins: [{
ptype: 'treeviewdragdrop'
}]
},
height: 350,
width: 400,
title: 'Directory Listing',
renderTo: 'tree-example',
collapsible: true
});
});




in foo.xml I tried:


<nodes>
<node>
<id>1</id>
<text>Mommy</text>
<node>
<id>2</id>
<text>Kiddie</text>
</node>
</node>
</nodes>


which gives me mommy and kiddie on the same level. I also tried:



<nodes>
<node>
<id>1</id>
<text>Mommy</text>
<nodes>
<node>
<id>2</id>
<text>Kiddie</text>
</node>
</nodes>
</node>
</nodes>


Which brings the same result. Using the suggested patch, I'm able to load the 2nd XML data structure and get expected result.

christophe.geiser
15 Jun 2011, 1:53 AM
Bumped into same problem (http://www.sencha.com/forum/showthread.php?134059-cannot-load-xml-nested-data-to-tree-(4.0.1))
Solved using real xpath extension with the help of this (http://www.sencha.com/forum/showthread.php?137126-real-xpath-selector&p=614326#post614326)

Cheers
C.

mankz
21 Dec 2011, 3:57 AM
BUMP

mankz
9 Feb 2012, 2:51 PM
BUMP, still broken in 4.1 B2

avrahqedivra
11 Sep 2012, 10:26 AM
Hi,

I'm new to Sencha Architect (MVC) ExtJS 4.1.1. I've been fighting for a couple of days with Stores based on Models using Associations (HasMany & BelongsTo)

I receive an XML formated menu description that I would like to render, (like the simplified following)

<?xml version="1.0" encoding="UTF-8"?>
<document>
<menu>
<categorie>
<item>
<application>xxxx</application>
<code/>
<libelle>xxxx</libelle>
<url>www.xxxx.com</url>
<target>xxxxx</target>
</item>
<item>
<application>xxxx</application>
<code/>
<libelle>xxxx</libelle>
<url>www.xxxx.com</url>
<target>xxxxx</target>
</item>
<item>
<application>xxxx</application>
<code/>
<libelle>xxxx</libelle>
<url>www.xxxx.com</url>
<target>xxxxx</target>
</item>
</categorie>
<categorie>
<item>
<application>xxxx</application>
<code/>
<libelle>xxxx</libelle>
<url>www.xxxx.com</url>
<target>xxxxx</target>
</item>
</categorie>
</menu>

<status>true</status>
<message/>
</document>


Here is my code :

onXmlstoreLoad: function(store, records, successful, operation, options) {
if ((records === null) || (records.length === 0))
return;


var doc = store.each(function(document) {
console.log('status = ' + document.get('status'));
console.log('message = ' + document.get('message'));
console.log('');


var menuList = document.menuList();
console.log('\tmenuList count : ' + menuList.getCount());
menuList.each(function(menu) {


var categorieList = menu.categorieList();
console.log('\t\tcategorie count : ' + categorieList.getCount());
categorieList.each(function(categorie) {


var itemList = categorie.itemList();
console.log('\t\t\titemList count : ' + itemList.getCount());
itemList.each(function(item) {
console.log('\t\t\t\titem application = ' + item.get('application'));
console.log('\t\t\t\titem code = ' + item.get('code'));
console.log('\t\t\t\titem libelle = ' + item.get('libelle'));
console.log('\t\t\t\titem url = ' + item.get('url'));
console.log('\t\t\t\titem target = ' + item.get('target'));
});
});
});
});
}



It just works fine, only first record is found (and displayed). All .getCount() returns '1'.

Any clue?

Thanks

Animal
20 Mar 2013, 1:13 AM
I agree that patch makes total sense when reading only immediate child nodes in a tree structure.

But it would change lenient behaviour when reading a flat record list for a grid.

For an example of this, check examples/grid/xml-grid.js

It does not specify a "root" from which to extract its records, just the selector "Item"

And <Item> elements are buried in <ItemSearchResponse><Items>

It would be a change in behaviour, and less flexible.

If you only require immediate child nodes, you should specify



record: '>node'

mankz
20 Mar 2013, 1:18 AM
Then I think this should be handled/solved by XmlStore, or the TreePanel somehow. I can't see why I as an implementor should have to worry about something as trivial as loading nested data into a view made for showing nested records.

evant
20 Mar 2013, 1:25 AM
I don't think it's a good idea for the tree to be reaching into the reader and making assumptions about how the data is formatted. Especially since the current behaviour allows for nesting at any level by default.

mankz
20 Mar 2013, 1:27 AM
Ok, any way you solve it is fine - question remains: How do I as an implementor show a full tree coming from XML in a TreePanel? It.should.just.work. :)

evant
20 Mar 2013, 1:29 AM
Via setting the record property:



record: '>foo'


It's already supported, it just needs some extra docs to elaborate.

Animal
20 Mar 2013, 2:11 AM
Then I think this should be handled/solved by XmlStore, or the TreePanel somehow. I can't see why I as an implementor should have to worry about something as trivial as loading nested data into a view made for showing nested records.

Likewise, someone implementing a grid, and loading a flat list of records might say that they do not see why they as an implementor should have to worry about what level of nesting their record element is at.

Another config option here would be just adding complexity when the simple answer is a more specific selector for the less common situation. (I'm making an assumption here I know, that loading flat lists is more common than loading tree-structured data!)

I will add documentation making this explicit and adding advice for those loading tree-structured data.

mankz
20 Mar 2013, 2:20 AM
Ok, as long as this info is visible in the docs it's all good. It would also be great to update one of the tree samples to show how to use an XML Tree like this, as it feels like the most basic usage.

mankz
20 Mar 2013, 2:33 AM
This is neat, just cleared another of my overrides :)