parsing - ExtJS 4.2.2 - XML Parser Using Child Nodes Properties on Root Object -
parsing - ExtJS 4.2.2 - XML Parser Using Child Nodes Properties on Root Object -
i having problem xml parsing in extjs 4.2.2, when have nested kid nodes.
in illustration below, show xml getting user has 'type' attribute , tool has 'type' attribute. (the users 'type' string, tools 'type' object, i'm not sure if related problem).
my problem xml parser seems picking both 'type' attributes when mapping user object , getting confused, resulting in user's 'type' attribute beingness 'null' (where expecting string 'normal').
code examples:
xml example:
class="lang-xml prettyprint-override"><user> <id>1</id> <username>john smith</username> <type>normal</type> <tools> <tool> <id>100</id> <name>drill</name> <type> <size>5.3</size> <model>brand name</model> </type> </tool> </tools> </user> store example:
class="lang-js prettyprint-override">ext.create('ext.data.store', { autoload: true, model: 'user', data: xmldata, proxy: { type: 'memory', reader: { type: 'xml', record: 'user' } } }); model example:
class="lang-js prettyprint-override">ext.define('user', { extend: 'object', fields: [ {name: 'id'}, {name: 'username'} {name: 'type'} ], hasmany: { model: 'tool', name: 'tools', reader: { type: 'xml', record: 'tool' } }); ext.define('tool', { extend: 'object', fields: [ {name: 'id'}, {name: 'name'} ] }); any help much appreciated.
thanks!
after much digging around trying different possible solutions..
i found simple way accomplish goal!
for else having same problem, managed work around adding 'mapping' top level class's 'type' field appended '>' in front end of property name.
{name: 'type', mapping: '>type'}
example:
class="lang-js prettyprint-override">ext.define('user', { extend: 'object', fields: [ {name: 'id'}, {name: 'username'} {name: 'type', mapping: '>type'} ], hasmany: { model: 'tool', name: 'tools', reader: { type: 'xml', record: 'tool' } }); hope helps else too!
thanks.
xml parsing extjs
Comments
Post a Comment