在Sencha Touch中显示嵌套模型数据的问题XTemplate
问题描述:
我使用Sencha Touch在列表模板中显示嵌套(关联)模型数据,但我只能获取显示的根模型数据。我的模型是属于客户的预约,客户有许多预约。我的模型代码:在Sencha Touch中显示嵌套模型数据的问题XTemplate
Customer = Ext.regModel('Customer', {
hasMany: { model: 'Appointments', name: 'appointments' },
fields: [
{ name: 'id', type: 'integer' },
{ name: 'firstName', type: 'string' },
{ name: 'lastName', type: 'string' },
{ name: 'email', type: 'string' },
{ name: 'secondary_email', type: 'string' },
{ name: 'homePhone', type: 'string' },
{ name: 'mobilePhone', type: 'string' },
{ name: 'dob', type: 'date', dateFormat: 'Y-m-d' },
{ name: 'allowLogin', type: 'boolean' },
{ name: 'emailReminders', type: 'boolean' },
{ name: 'reminders_to_stylist', type: 'boolean' },
{ name: 'fullName',
convert: function(value, record) {
var fn = record.get('firstName');
var ln = record.get('lastName');
return fn + " " + ln;
} }
]
});
Appointment = Ext.regModel('Appointment', {
belongsTo: { model: 'Customer', name: 'customer' },
fields: [
{ name: 'id', type: 'string' },
{ name: 'startTime', type: 'date', dateFormat: 'c' },
{ name: 'customer_id', type: 'integer' },
{ name: 'startTimeShort',
convert: function(value, record) {
return record.get('startTime').shortTime();
}
},
{ name: 'endTimeShort',
convert: function(value, record) {
return record.get('endTime').shortTime();
}
},
{ name: 'endTime', type: 'date', dateFormat: 'c' }
]
});
并使用的xtype我的面板:名单看起来像:
var jsonPanel = {
title: "Appointments",
items: [
{
xtype: 'list',
store: appointmentStore,
itemTpl: '<tpl for="."><span id="{id}">{startTimeShort} - {endTimeShort} <tpl for="customer"><span class="customer">{firstName}</span></tpl></span></tpl>',
singleSelect: true,
onItemDisclosure: function(record, btn, index) {
Ext.Msg.alert('test');
}
}
]
};
嵌套的数据会从JSON加载并似乎正确加载进店 - 当我调试约会存储对象从Appointment模型中加载,我看到appointment.data.items数组对象具有CustomerBelongsToInstance对象,并且该对象的数据对象包含正确的模型数据。 startTime和endTime字段在列表中正确显示。
我怀疑我要么没有正确使用项目模板标记,要么可能存在一些奇怪的依赖关系,我必须从具有“拥有多个”关联的模型开始,而不是“属于“如厨房水槽演示中所示。
我无法找到任何使用这种类型的关联的例子,所以任何帮助表示赞赏。
答
看起来像您的客户hasmany协会正在分配约会时,它应该是约会,这是该模型的名称。