Sencha touch extxtemplate的问题

Sencha touch extxtemplate的问题,sencha-touch,extjs,sencha-touch-2,Sencha Touch,Extjs,Sencha Touch 2,我试图创建一个XTemplate来显示dataview中每个项的一对多关系显示 我想将TransactionType显示为列表项的标题,并且我必须循环该ActionSummary的ActionList并显示每个操作项的名称 但下面的代码失败了 型号 这里的行动模式 Ext.define('MyMobile.model.ActionModel', { extend: 'Ext.data.Model', config: { fields: [ { name: 'Action'

我试图创建一个XTemplate来显示dataview中每个项的一对多关系显示

我想将TransactionType显示为列表项的标题,并且我必须循环该ActionSummary的ActionList并显示每个操作项的名称

但下面的代码失败了

型号

这里的行动模式

Ext.define('MyMobile.model.ActionModel', {
extend: 'Ext.data.Model',
config: {
    fields: [
        { name: 'Action', type: 'string' },            
        { name: 'Count', type: 'int' },            
        { name: 'Id', type: 'int' },
        { name: 'CurrentStatus', type: 'string' }
    ]
}
});
行动摘要模型

Ext.define('MyMobile.model.ActionSummaryModel', {
extend: 'Ext.data.Model',
config: {
    fields: [
        { name: 'Id', type: 'int' },
        { name: 'TransactionType', type: 'string' }

    ]
    ,
    hasMany: {
        model: 'MyMobile.model.ActionModel',
        name: 'ActionList'
    }
}
});
商店

Ext.define('MyMobile.store.ActionSummaryStore'{ 扩展:“Ext.data.Store”

config: {
    model: 'MyMobile.model.ActionSummaryModel',

    proxy: {
        type: 'ajax',
        url: 'home/GetActionSummary',
        method: 'GET',
        reader: {
            type: 'json'
        }
    }
}
});
查看

Ext.define('MyMobile.view.ActionListView', {
extend: 'Ext.dataview.List',
xtype: 'actionsummary',
id: 'actionsummaryList',

config: {
    title: 'Actions',

    store: 'ActionSummaryStore',
    emptyText: 'Loading action items...',
    itemTpl: Ext.create('Ext.XTemplate', '<tpl for=".">',
                                            '<div><p class="action-text">{TransactionType}</p>',
                                                  '<tpl for="ActionList"><tpl for=".">',       
                                                        '<p>{Action}</p>',  
                                                         '<span class="action-count">Count:{Count}</span><br>',
                                                         '<span class="action-status">Current Status: {CurrentStatus}</span>',
                                                    '</tpl></tpl>',          
                                             '</div>',
                                           '</tpl>'

                       )
 }
 });
如果我硬编码这个JSON数据而不是存储它,它就可以工作。

Ext.define('WorksMobile.view.ActionListView', {
extend: 'Ext.dataview.List',
xtype: 'actionsummary',
id: 'actionsummaryList',

config: {
    title: 'Actions',


    data:[{"Id":1,"TransactionType":"Transaction 1","ActionList":[{"Id":1,"Count":4,"Action":"Action Item 1","CurrentStatus":"Open"},{"Id":2,"Count":14,"Action":"Action Item 3","CurrentStatus":"Open"},{"Id":3,"Count":44,"Action":"Action Item 5","CurrentStatus":"Close"}]}],

    emptyText: 'Loading action items...',
    itemTpl: Ext.create('Ext.XTemplate', '<tpl for=".">',
                                            '<div><p class="action-text">{TransactionType}</p>',
                                                  '<tpl for="ActionList"><tpl for=".">',  
                                                        '<p>{Action}</p>',  
                                                         '<span class="action-count">Count:{Count}</span><br>',
                                                         '<span class="action-status">Current Status: {CurrentStatus}</span>',
                                                    '</tpl></tpl>',          
                                             '</div>',
                                           '</tpl>'

                       )
}
});
Ext.define('WorksMobile.view.ActionListView'{
扩展:“Ext.dataview.List”,
xtype:“操作摘要”,
id:“actionsummaryList”,
配置:{
标题:“行动”,
数据:[{“Id”:1,“TransactionType”:“Transaction 1”,“ActionList”:[{“Id”:1,“Count”:4,“Action”:“Action Item 1”,“CurrentStatus”:“Open”},{“Id”:2,“Count”:14,“Action”:“Action Item 3”,“CurrentStatus”:“Open”},{“Id”:3,“Count”:44,“Action”:“Action Item 5”,“CurrentStatus”:“Close”}],
emptyText:“正在加载操作项…”,
itemTpl:Ext.create('Ext.XTemplate','',
“

{TransactionType}

”, '', “{Action}

”, '计数:{Count}
', '当前状态:{CurrentStatus}', '', '', '' ) } });
我不知道为什么上面的XTemplate不能与JSON存储一起工作。它只显示事务类型、平均标题,而不显示嵌套项的详细信息。请对此提供帮助

编辑:过了一段时间,我意识到存储区没有加载关系。它没有在每个ActionSummary下显示ActionList。是否存在映射问题

编辑2
我删除了ActionSummaryModel中的hasMany映射,并添加了一个字段{name:'ActionList',键入:'auto'},然后它就开始工作了。但是我想通过与hasManybelongsTo的关系来完成它。非常感谢您的帮助!!

我将列出使代码正常工作的所有步骤,如下所示:

首先,在存储中添加
autoLoad
,以便在实例化时从远程源自动加载相关存储

model: 'MyMobile.model.ActionSummaryModel',
autoLoad: true
其次,您需要使用
associationKey
,它是数据中要从中读取关联的属性的名称,而不是
hasMany
关联中的
name

hasMany: {
    model: 'MyMobile.model.ActionModel',
    associationKey: 'ActionList'
}
最后,在您看来,您需要通过更改以下内容对您的
tpl
进行一些更改:

<tpl for="ActionList">

关联型号名称的复数形式:

<tpl for="actionmodels">     


顺便说一句,记住在app.js中包含所有相应的视图、商店和模型,以使其正常工作。希望它能有所帮助:)

您有没有找到一个好的解决方案,可以与模型和关联一起工作?
<tpl for="actionmodels">