XML嵌套节点到Extjs 4中的数组

时间:2013-05-10 19:34:44

标签: xml xml-parsing extjs-mvc extjs4.2

我对博客有以下结构:

<channel>
 <item>
 <title>title of post</title>
(...)
 <gallery folder="path_to_gallery">
  <image>path_to_image</image>
  <image>path_to_other_image</image>
 </gallery>
 <gallery folder="path_to_other_gallery">
  <image>path_to_new_image</image>
  <image>path_to_other_new_image</image>
 </gallery>
</item>
</channel>

现在为此,我有一个带有hasManyAssociation的extjs模型。除了画廊项目之外,上部模型工作正常。我的模型看起来像这样:

父模型:

Ext.define('App.model.News', {
    extend: 'Ext.data.Model',
    config: {
        fields: [{
            name: 'title'
        }, {
            name: 'description'
        }, {
            name: 'thumbnail'
        }, {
            name: 'pubDate',
            type: 'date'
        }],
        hasMany: {
            associationKey: 'gallery',
            primaryKey: 'folder',
            model: 'App.model.Gallery'
        }
    }
});    

儿童模特:

Ext.define('App.model.Gallery', {
    extend: 'Ext.data.Model',
    config: {
        fields: [{
            name: 'image'
        }, {
            mapping: '@folder',
            name: 'folder'
        }]
    }
});

任何人都知道我做错了什么?

1 个答案:

答案 0 :(得分:0)

我最终没有为画廊使用模型,只是访问原始数据。这允许我使用节点,就像DOM元素一样。

供将来参考,这是一个代码示例:

itemTapped: function(dataview, index, target, record, e, eOpts) {

    var html = '<h2>' + record.get('title') + '</h2>';
    html += record.get('encoded');

    var raw = this.down('#mylist').getStore().data.items[index].raw;
    //further processing happens here. 'raw' contains the complete item-tag as a 
    //DOM object, so we can use querySelectorAll, getAttribute, etc.

}