我正在使用:
Ember 1.10.0 Ember Data 1.0.0-beta.15
我有一个这样的模型:
//models//acceptedtask.js
import DS from "ember-data";
export default DS.Model.extend({
userAggregateId: DS.attr('number'),
taskAggregateId: DS.attr('number'),
name: DS.attr('string')
});
我从服务器上取回来了:
{"acceptedTask":{"id":5,"userAggregateId":1,"taskAggregateId":3,"name":"Clean table"}}
每当我得到这个json back ember时会抛出以下错误:
Error: Assertion Failed: You must include an `id` for task-management@model:acceptedtask: in an object passed to `push`
at new Error (native)
at Error.EmberError (http://localhost:4200/assets/vendor.js:22992:23)
at Object.Ember.assert (http://localhost:4200/assets/vendor.js:14489:15)
at Ember.Object.extend.push (http://localhost:4200/assets/vendor.js:74317:15)
at http://localhost:4200/assets/vendor.js:74783:24
at Object.Backburner.run (http://localhost:4200/assets/vendor.js:10749:27)
at ember$data$lib$system$store$$_adapterRun (http://localhost:4200/assets/vendor.js:74759:32)
at http://localhost:4200/assets/vendor.js:74780:16
at tryCatch (http://localhost:4200/assets/vendor.js:60990:16)
at invokeCallback (http://localhost:4200/assets/vendor.js:61002:17)
有人能帮我这个吗?我觉得自己错过了一些基本的东西,因为类似的问题拖累了一半的互联网:(
谢谢,
汤姆
答案 0 :(得分:1)
我使用了你的模型和回应。但是,要使其正确填充,我必须更改
的响应{"acceptedTask":{"id":5,"userAggregateId":1,"taskAggregateId":3,"name":"Clean table"}}
到
{"acceptedtask":{"id":5,"userAggregateId":1,"taskAggregateId":3,"name":"Clean table"}}
除此之外,它看起来不错。但是,我收到了以下警告,而不是您指出的错误:
"WARNING: Encountered "acceptedTask" in payload, but no model was found for model name "acceptedTask"