0

我正在尝试遵循此处给出的小猫示例 http://www.sencha.com/blog/dive-into-dataview-with-sencha-touch-2-beta-2#comment_form

我有复杂的组件,其中我的数据属性之一是对象列表。我正在使用 setItems 方法将我的列表对象映射到 Ext.Container。但是,它似乎不起作用。在警报点,我将对象视为未定义。但是如果我将 setItems 更改为 setText,那么我会得到对象的字符串表示形式。有人对我缺少什么有任何建议吗?

Ext.define('MyListItem', {

    extend: 'Ext.dataview.component.DataItem',
    requires: ['Ext.Container'],
    xtype: 'mylistitem',   

    config: {
        sponsor: true,
        dataMap: {
            getSponsor: {
                setItems: 'sponsor'
            }
        }
    },

    applySponsor: function(config) {
        // I put an alert here to see if I get getSponsor() but the object I get here is undefined
        alert(this.getSponsor());
        return Ext.factory(config, Ext.Container, this.getSponsor());
    },

    updateSponsor: function(newNameButton, oldNameButton) {
        if (oldNameButton) {
            this.remove(oldNameButton);
        }

        if (newNameButton) {
            this.add(newNameButton);
        }
    },

    onSponsorTap: function(button, e) {
        var sponsors = record.get('sponsor');
        //my specific action
    }
});

Ext.define('MyApp.model.Sponsors', {
    extend: 'Ext.data.Model',
    xtype:'Sponsors_m',
    config: {
        fields: [
            {name: 'level', type: 'auto'},
            {name: 'id', type: 'int'},
            {name: 'sponsor', type: 'Sponsor'}
        ]
    }
});

Ext.define('MyApp.model.Sponsor', {
    extend: 'Ext.data.Model',
    xtype:'Sponsor_m',
    config: {
        fields: [
            {name: 'name', type: 'auto'},
            {name: 'image', type: 'auto'},
            {name: 'url', type: 'auto'},
            {name: 'description', type: 'auto'}
        ]
    }
});
4

1 回答 1

0

唔...

您的模型中没有任何名为“赞助商”的字段

config: {
    sponsor: true,
    dataMap: {
        getSponsor: {
            ***setItems: 'sponsor'*** //this supposed to map your component to the datafield
        }
    }
},

尝试将粗体字体更改为您的字段名称(setItems:'name')

如果我没记错的话,更新方法的参数命名有严格的规定,即:***以“赞助商”作为配置名称的示例

新赞助商,旧赞助商

所以赞助商的更新方法应该是:

updateSponsor: function(**newSponsor**, **oldSponsor**) {
        if (oldSponsor) {
            this.remove(oldSponsor);
        }

        if (newSponsor) {
            this.add(newSponsor);
        }
    },
于 2013-04-05T08:18:02.940 回答