【问题标题】:XML nested nodes to array in Extjs 4XML嵌套节点到Extjs 4中的数组
【发布时间】:2013-05-10 19:34:44
【问题描述】:

我的博客结构如下:

<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'
        }]
    }
});

有人知道我做错了什么吗?

【问题讨论】:

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


    【解决方案1】:

    我最终没有为画廊使用模型,而只是访问原始数据。这让我可以像使用 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.
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多