gpt4 book ai didi

javascript - 模型未使用 Ember.js 和 WebApiAdapter 序列化

转载 作者:行者123 更新时间:2023-11-30 08:03:43 25 4
gpt4 key购买 nike

我正在尝试使用 Ember.js MVC4 Spa Template 使用我自己的模型,但我没有让它工作。

目前,服务器端代码正在运行。浏览器的结果是正确的。但是 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;
}
}
});

奥芬塔尔:

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;
},
}
});

当我从我的 Controller 获得“患者”列表时,数据模型被正确填充(我可以在 Chrome Ember 插件中检查它。)当我使用患者 ID 执行操作时,我收到错误:“错误加载路线时:类型错误:无法设置未定义的属性“存储”

谢谢!

最佳答案

您是否在 app/routes 文件夹中添加了正确的路由器,在 app/controllers 文件夹中添加了 Controller ,以及相应的 View 和模板?请随时提供指向您的示例解决方案的链接,以便我下载并查看。

=== 2014 年 2 月 22 日更新 ===我修复了代码。您应该能够从 https://www.dropbox.com/s/4j3vbczqr4nx68m/EmberVSTemplateModified.zip 下载修改后的解决方案.您应该对这两个目录执行 windiff 以查看更改。我需要更改一些地方以使其适用于您的场景,包括:

  1. patient.js,直接从 RESTSerialzer 扩展,并添加 extractSingle 实现。
  2. 修改patsucheautocomplete.hbs模板
  3. 添加了 patient\index.hbs 。您应该能够删除 patient.hbs 文件
  4. paitentview.js(可能不是必需的,因为它都是默认的)
  5. 修改了 controllers\htmlhelperextensions.cs,使其在 Debug模式下对子文件夹模板正常工作。

关于javascript - 模型未使用 Ember.js 和 WebApiAdapter 序列化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21858983/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com