Model 在XTemplate中加载关联的模型数据

Model 在XTemplate中加载关联的模型数据,model,sencha-touch,sencha-touch-2,associations,Model,Sencha Touch,Sencha Touch 2,Associations,在过去的两天里,我搜索了很多,但找不到解决方案。以下是我的问题描述: 我有一个Sencha Touch应用程序,有一个简单的列表作为视图,两个模型(CartItem和Article)和两个对应的商店(CartItems和Articles) CartItem模型与文章模型具有“hasOne”关联 列表视图应显示所有CartItems以及相关文章的描述 应该没那么难吧?一般来说,这些协会都很有效,我通过以下途径获得了文章描述: > Ext.getStore('cartItemStore').g

在过去的两天里,我搜索了很多,但找不到解决方案。以下是我的问题描述:

我有一个Sencha Touch应用程序,有一个简单的列表作为视图,两个模型(CartItem和Article)和两个对应的商店(CartItems和Articles)

CartItem模型与文章模型具有“hasOne”关联

列表视图应显示所有CartItems以及相关文章的描述

应该没那么难吧?一般来说,这些协会都很有效,我通过以下途径获得了文章描述:

> Ext.getStore('cartItemStore').getAt(0).getArticle().get('description')
"Example article 1"
但我无法在列表中显示此描述

我已经尝试过的是使用

  1) <tpl for="Article">{description}</tpl>
     -> doesn't display anything. Neither data nor an error.
  2) {Article.description}
     in combination with:
     http://appointsolutions.com/2012/07/using-model-associations-in-sencha-touch-2-and-ext-js-4/
     -> f***ed up my whole storage-system :/
Article.js(文章模型)

CartItems.js(CartItem商店)

Articles.js(文章商店)


哦,上帝,对不起打扰你了。没人说我必须执行死刑

cartItem.setArticle(myArticle)

在我进入协会之前-

Ext.define('assoTempl.view.Main', {
    extend: 'Ext.dataview.List',
    xtype: 'main',
    config: {
        store: 'cartItemStore',
        scrollable: 'vertical',
        itemTpl: '<span>{cart_pos} <tpl for="Article">{description}</tpl></span>'
    }
});
Ext.define('assoTempl.model.CartItem', {
    extend: 'Ext.data.Model',

    config: {
        fields: [
            { name: 'cart_pos'},
            { name: 'article_id'}
        ],
        proxy: {
            type: 'memory'
        },
        hasOne: {
            model: 'assoTempl.model.Article',
            name: 'Article',
            foreignKey: 'ANr',
            foreignStore: 'ArticleStore'
        }
    }
});
Ext.define('assoTempl.model.Article', {
    extend: 'Ext.data.Model',

    config: {
        fields: [
            { name: 'ANr', type: 'int' },
            { name: 'description', type: 'String' }
        ],
        proxy: {
            type: 'memory'
        }
    }
});
Ext.define("assoTempl.store.CartItems", {
    extend: "Ext.data.Store",
    requires: ['Ext.data.proxy.Sql'],
    config: {
        storeId: 'cartItemStore',
        model: "assoTempl.model.CartItem",
        data: [
            {cart_pos:0, article_id:0},
            {cart_pos:1, article_id:1}
        ],
        autoLoad: true
    }
});
Ext.define("assoTempl.store.Articles", {
    extend: "Ext.data.Store",
    requires: ['Ext.data.proxy.Sql'],
    config: {
        storeId: 'articleStore',
        model: "assoTempl.model.Article",
        data: [
            {ANr:0, description:'Example article 1'},
            {ANr:1, description:'I am article 2'}
        ],
        autoLoad: true
    }
});