【问题标题】:Problem displaying nested model data in Sencha Touch XTemplate在 Sencha Touch XTemplate 中显示嵌套模型数据时出现问题
【发布时间】:2011-08-22 19:38:00
【问题描述】:

我正在使用 Sencha Touch 在列表模板中显示嵌套(关联)模型数据,但我只能获取要显示的根模型数据。我的模型是属于客户的约会,客户有很多约会。我的型号代码:

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 字段在列表中正确显示。

我怀疑我没有正确使用项目模板标记,或者可能存在一些奇怪的依赖关系,我必须从具有“有很多”关联而不是“属于”关联的模型开始如厨房水槽演示所示。

我找不到任何使用这种关联类型的示例,因此不胜感激。

【问题讨论】:

    标签: javascript sencha-touch extjs


    【解决方案1】:

    看起来您的 Customer hasmany 关联正在分配 Appointments,而它应该是该模型的名称的约会。

    【讨论】:

      猜你喜欢
      • 2012-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-05
      • 1970-01-01
      • 2012-09-14
      相关资源
      最近更新 更多