我有一个从 API 查询的模型:
App.Deal = DS.Model.extend({
name: DS.attr('string'),
value_in_cents: DS.attr('number'),
closed_time: DS.attr('date'),
user: DS.attr('object'),
company: DS.attr('object')
});
API 返回如下内容:
{
pagination: { page: 1, total: 10 },
entries: [ deal1, deal2, deal3, deal4 ]
}
我已将我的适配器更新为以下内容:
App.Adapter = DS.RESTAdapter.extend({
url: 'http://api.pipelinedeals.com/api/v3',
serializer: DS.RESTSerializer.extend({
extractMany: function(loader, json, type, records) {
var root = this.rootForType(type);
var roots = this.pluralize(root);
formattedJson = {};
formattedJson[roots] = json.entries;
delete formattedJson.pagination;
this._super(loader, formattedJson, type, records);
}
})
});
newJson
有我想要的格式,但我收到以下错误:
Uncaught Error: assertion failed: You tried to use a attribute type (object) that has not been registered ember-1.0.0-rc.2.js:52