【发布时间】:2014-09-19 14:21:45
【问题描述】:
目前正在使用 Ember-cli 开发应用程序,但在使用具有 2 个单词和关系的模型时遇到了一些困难。
模范居民个人资料
//models/residents-profile.js
DS.Model.extend({
firstName: DS.attr('string'),
lastName: DS.attr('string'),
picture: DS.attr('string'),
phone: DS.attr('string'),
gender: DS.attr('string'),
residentsAccount: DS.belongsTo('residentsAccount')
}
** 模拟居民账户**
//models/residents-account.js
DS.Model.extend({
email: DS.attr('string'),
password: DS.attr('string'),
profileId: DS.attr('number'),
residentsProfile: DS.belongsTo('residentsProfile', this.profileId),
});
居民路线上的模型挂钩:
//routes/residents.js
model: function() {
return Ember.RSVP.hash({
residentsProfile: this.store.find('residentsProfile'),
residentsAccount: this.store.find('residentsAccount')
})
}
当我尝试仅获取居民个人资料时,我收到一个错误“residents.index Cannot read property 'typeKey'”
但是,如果我从居民个人资料中删除关系键并仅调用居民个人资料,则可以正确获取数据。
我正在使用 RESTAdapter 和一个 Restful API,
模型单独返回,服务器响应如下:
GET /residentsProfile { “居民档案”:[{ “身份证”:20, “图片”:空, “电话”:空, "firstName": "洛基", "lastName": "巴尔博亚", “blockId”:空, “单位标识”:空, "createdAt": "2014-09-17 19:54:28", "updatedAt": "2014-09-17 19:54:28", “居民账户”:[5] }] }
GET /residentsAccount { “居民账户”:[{ “身份证”:5, “电子邮件”:“rocky@balboainc.me”, “管理员”:假, “居民”:是的, "profileId": 20, "createdAt": "2014-09-17 19:54:29", "updatedAt": "2014-09-17 19:54:29", “居民简介”:[20] }] }
编辑
除了@Kingpin2k 提出的更改,这些更改是正确的,我使用 setupcontroller 的方式如下:
setupController: function(controller,
controller.set('residentsAccount', models.residentsAccount);
controller.set('residentsProfile', models.residentsProfile);
}
现在一切正常。
【问题讨论】:
标签: ember.js ember-data ember-cli