简体   繁体   English

在 Sencha Touch XTemplate 中显示嵌套的 model 数据时出现问题

[英]Problem displaying nested model data in Sencha Touch XTemplate

I am using Sencha Touch to display nested (associated) model data in a list template but I can only get the root model data to display.我正在使用 Sencha Touch 在列表模板中显示嵌套(关联)model 数据,但我只能获取要显示的根 model 数据。 My models are an Appointment which belongs to a Customer, and Customers have many Appointments.我的模型是属于客户的约会,客户有很多约会。 My model code:我的 model 代码:

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

And my panel using an xtype: list looks like:我使用 xtype: list 的面板看起来像:

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

The nested data gets loaded from JSON and appears to be loading correctly into the store - when I debug the appointment store object loaded from the Appointment model, I see that the appointment.data.items array objects have a CustomerBelongsToInstance object and that object's data object does contain the correct model data. The nested data gets loaded from JSON and appears to be loading correctly into the store - when I debug the appointment store object loaded from the Appointment model, I see that the appointment.data.items array objects have a CustomerBelongsToInstance object and that object's data object确实包含正确的 model 数据。 The startTime and endTime fields display correctly in the list. startTime 和 endTime 字段在列表中正确显示。

I have a suspicion that I am either not using the item template markup correctly, or perhaps there is some weird dependency where I would have to start from the model that has the "has many" association rather than the "belongs to" as shown in the kitchen sink demo.我怀疑我没有正确使用项目模板标记,或者可能存在一些奇怪的依赖关系,我必须从 model 开始,它具有“有很多”关联而不是“属于”,如图所示厨房水槽演示。

I wasn't able to find any examples that used this type of association so any help is appreciated.我找不到任何使用这种关联的示例,因此不胜感激。

Looks like your Customer hasmany association is assigning Appointments when it should be appointment which is the name of that model.看起来您的客户有许多协会正在分配约会,而它应该是约会,这是 model 的名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM