parsing deeply nested xml in sencha touch

流过昼夜 提交于 2019-12-12 00:01:03

问题


I'm trying to parse a xml file and I'm having problems with a really simple nested tag but every example I have seen just takes the easy way of reading not nested xml tags, or plainly changing the xml (I can't do that). So my question is: in Sencha touch 1.1, how can I configure the model to load just one property which is nested inside a couple of tags? I tried this:

    Ext.regModel('article',{
    fields: [
        {name:'Headline',type:'string'},
        {name:'Summary',type:'string'},
        {name:'Body',type:'string'},
        {name:'Thumbs',mapping:'Photos > Thumbnail'}
    ],
});

and this would be an xml item:

<Headline>
blah blah blah
</Headline>
<Body>
blah blah blah
</Body>
<Summary>
blah blah
</Summary>
<Photos>
<Photo src="big_image_link" width="400" height="276"/>
<Thumbnail src="little_image_link" width="110" height="80"/>
</Photos>
</item>

the model is parsing the headline, summary and body just fine, the problem comes with the Photo and Thumbnail inside the "Photos" tag, I have tried with associations in every way I've seen documented but it didn't work in any case, I'm just interested in the Thumbnail src property, I don't know why it is THAT hard.

edit: I changed the code to reflect how I got to the 'Thumbnail' tag when I edited a local copy of the xml to be like

<Thumbnail>image_link</Thumbnail>

But now I need to access the 'src' and I don't know how the mapping should change from

mapping:'Photos > Thumbnail'

And I've tried: Photos > Thumbnail, Photos > Thumbnail.src, Photos > Thumbnail > src, Photos > Thumbnail @src, and a couple more ways, still no answer.


回答1:


Your code seems right. You only need to change mapping:'@src' to mapping:'src' i.e. with out the @ character.




回答2:


I ended up parsing the xml with plain js and adding each object to the store, hopefully sencha touch 2 will have a working xml reader on it's final release.



来源:https://stackoverflow.com/questions/8401968/parsing-deeply-nested-xml-in-sencha-touch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!