PDA

View Full Version : Searching through raw for nested data



kortovos
15 Oct 2010, 6:19 AM
I am trying to find a way to read nested xml-data, with variable number of certain nested data. In the example below are 2 contacts , but there could also be 5 contacts. I was thinking about using the convert function in a model to construct an array with all contacts. But I cannot get access to the raw data, though it is present in the record of the convertfunction. Anybody got any idea how to acces the raw data? Or have a better way of reading variable number of nested xml-data?


<order>
<id>1</id>
<other attributes>...</other attributes>
<contacts>
<contact>
<name>Jef</name>
</contact>
<contact>
<name>Jill</name>
</contact>
</contacts>
</order>
Ext.regModel('Order', {
fields : [
{
name: 'id',
type: 'integer',
defaultValue: 666
},{
name:'contact',
mapping: 'contacts',
convert: function(v, rec){
console.log(rec);
.... (searching raw data for contacts)
}
}]22857

kortovos
18 Oct 2010, 11:44 PM
I have made absolutely no headway in my search to be able to read nested xml data.

This example doesn't work. It doesn't contain any of the contacts after 'order' has been read.

,hasMany:[{model: 'contact', mapping:'contacts', name:'contacts',foreignKey:'order_id', ownerModel:'order', primaryKey:'id',
storeConfig:{
model: 'contact',
proxy: {
type:'ajax',
id: 'id'
},reader: {
type: 'xml',
root: 'contact'
}
}}],

And when I try something like this I get:
Uncaught TypeError: Object [object Object] has no method 'querySelectorAll'

,{name: 'contact',mapping:'contacts > contact', convert: (function(){
var reader2 = new Ext.data.XmlReader({
record: 'contacts',
model : 'contact',
type: 'xml',
root:'contacts'
});
return function(v, n) {
return reader2.readRecords(n).records;
};
})()}

Plastic
19 Nov 2010, 10:19 AM
I got the same issue...

Have you solved it or someone have founded any solution?

kortovos
21 Nov 2010, 11:31 PM
I have found a way, though it is far from ideal. After the initial reading you take '((store.getProxy()).getReader()).xmlData' (with a read listener). This contains the raw xml data. After that you can put an xml reader on the raw data.


var reader = new Ext.data.XmlReader( {
model : 'Option',
type : 'xml',
root : 'd > order > car > options > option'
});

var result = reader.readRecords(rawData);

After that you connect the two entities with a foreign key, which references to the other entity. This works for me, but I still hope that they make a working and clear xml mapping example.

edspencer
22 Nov 2010, 5:41 PM
1.0 and before had some fairly limited XML reading support - especially when it came to loading associations. I've just committed a patch to finally allow nested XML data to be parsed natively based on your configured associations - this will be present in the next patch release (which is imminent).

See http://www.sencha.com/forum/showthread.php?115033-FIXED-583-nested-xml-complex-xml-cant-get-associations-to-work for more background. Sorry for the delay in implementing this.

Bunchofstring
29 Nov 2010, 6:32 PM
@Ed, glad you have a solution worked out. I gotta say, Sencha Touch is really awesome. However... for those of us who have been banging our heads against the same brick wall for days (i.e. me), can you give us an ETA for the next release, or maybe share your fix in the form of an override?

jameshenderson
18 Sep 2011, 1:38 PM
http://www.sencha.com/forum/showthread.php?115033-FIXED-583-nested-xml-complex-xml-cant-get-associations-to-work&p=650131#post650131

Thanks to bobbaluba (http://www.sencha.com/forum/member.php?284497-bobbaluba)!