Sencha Touch 2, nested XML node parsingValue

I am using a nested XML file and parsing it with "hasMany". I would appreciate if anyone could tell me how to read a value of type node '< >. I can easily read the attributes 'id' and 'val' of '' using mapping, but I also want to read the value of node, for example. 257411 in < type id = "3" val = "0"> 257411 I would appreciate if anyone could provide a suitable "mapping"

XML data:

<?xml version="1.0" encoding="ISO-8859-1"?> <basics id="744" name="social"> <number>302221</number> <types> <type id="3" val="0">257411</type> <type id="2" val="1081337">28213</type> <type id="1" val="263258">8645</type> <type id="5" val="0">3664</type> <type id="4" val="0">2246</type> <type id="9" val="0">1124</type> <type id="10" val="0">918</type> </types> </basics> 

Basic Ext.define model ("ap3.model.Basic", {expand: "Ext.data.Model",

 config: { fields: [ {name: 'id', mapping: '@id'}, {name: 'name', mapping: '@name'}, {name: 'number', mapping: 'number'} ], associations: [ { type: 'hasMany', model: 'apv3.model.Type', associationKey: 'types' }] } 

});

model Type Ext.define ("ap3.model.Type", {expand: "Ext.data.Model",

 config: { fields: [ {name: 'id', mapping: '@id'}, {name: 'val', mapping: '@val'}, {name: 'type', mapping: 'type'} ], proxy: { type: 'memory', reader: { type: 'xml', record: 'type' } } } 

});

+4
source share
2 answers

"mapping" also accepts a function:

 {name: 'id', mapping: '@id'}, {name: 'name', mapping: '@name'}, {name: 'number', mapping: function (node) { return (node.firstChild ? node.firstChild.nodeValue : null); }} 
+1
source

I do not know if this is considered the answer, but, having spent a lot of time on the same problem, I would say that this is a mistake in the structure: (

A few relevant links: fooobar.com/questions/1431158 / ... http://www.sencha.com/forum/showthread.php?209025-Nested-XML-reader-problem&p=838952&viewfull=1#post838952

Successfully nested JSON works fine. My advice is to switch to it or handle loading lower-level models manually (for example, write your own method that performs the hasMany association by creating a repository / reader and submitting this.raw.types to it).

0
source

All Articles