Wei*_*nix 1 javascript asp.net-mvc-4 ember.js asp.net-web-api
我正在尝试将Ember.js MVC4 Spa模板与我自己的模型一起使用,但我没有让它工作.
目前,服务器端代码正在运行.浏览器的结果是正确的.但Ember-Data或自定义WebApi - Serializer无法准备数据.
我有两个模特:病人:
App.Patient = DS.Model.extend();
App.Patient.reopen({
patientId: DS.attr('number'),
firstName: DS.attr('string'),
lastName: DS.attr('string'),
aufenthalte: DS.hasMany('aufenthalt'), //, { async: true }
fullName: function () {
return this.get('firstName') + ' ' + this.get('lastName');
}.property('firstName', 'lastName'),
});
App.PatientSerializer = DS.WebAPISerializer.extend({
primaryKey: 'patientId',
// ember-data-1.0.0-beta2 does not handle embedded data like they once did in 0.13, so we've to update individually if present
// once embedded is implemented in future release, we'll move this back to WebAPISerializer.
// see https://github.com/emberjs/data/blob/master/TRANSITION.md for details
extractArray: function (store, primaryType, payload) {
var primaryTypeName = primaryType.typeKey;
var typeName = primaryTypeName,
type = store.modelFor(typeName);
var data = {};
data[typeName] = payload;
data.aufenthalte = [];
var normalizedArray = payload.map(function (hash) {
hash.aufenthalte.map(function (aufenthalt) {
data.aufenthalte.push(aufenthalt);
});
hash.aufenthalte = hash.aufenthalte.mapProperty('aufenthaltId');
return hash;
}, this);
payload = data;
return this._super.apply(this, arguments);
},
normalizeHash: {
patient: function (hash) {
hash.patientId = hash.id;
return hash;
}
}
});
Run Code Online (Sandbox Code Playgroud)
Aufenthalt:
App.Aufenthalt = DS.Model.extend({
aufenthaltId: DS.attr('number'),
name: DS.attr('string'),
patientId: DS.attr('number'),
patient: DS.belongsTo('patient'),
});
App.AufenthaltSerializer = DS.WebAPISerializer.extend({
primaryKey: 'aufenthaltId',
normalizeHash: {
aufenthalte: function (hash) {
hash.aufenthaltId = hash.id;
return hash;
},
}
});
Run Code Online (Sandbox Code Playgroud)
当我从我的控制器获得"患者"列表时,数据模型被正确填充(我可以在Chrome Ember插件中查看它.)当我点击带有患者ID的动作时,我收到错误:"加载路线时出错:TypeError:无法设置未定义的属性'store'
谢谢!
您是否在app/routes文件夹中添加了正确的路由器,app/controllers文件夹中的控制器以及相应的视图和模板?随意粘贴您的示例解决方案的链接,以便我可以下载并查看.
=== 2014年2月22日更新===我修复了代码.您应该能够从https://www.dropbox.com/s/4j3vbczqr4nx68m/EmberVSTemplateModified.zip下载修改后的解决方案.你应该在两个目录上做一个windiff以查看更改.我需要更改一些地方以使其适用于您的方案,包括:
| 归档时间: |
|
| 查看次数: |
412 次 |
| 最近记录: |