我的Spring后端有一个JSON对象。如何在Ember应用商店中创建数据对象?
我试过了:
createObject() {
var _this = this;
$.getJSON('http://localhost:8080/object/getCard?id=24').then(function(response) {
_this.store.createRecord('cards/object/card', response);
});
}
JSON:
{
"id":24,
"fullName":"qwerty",
"form":"zzzzzzzzzzzz",
"leader": {
"id":23,
"fullName":"testName test",
"email":"emailTest"
}
}
我在Ember应用程序中有一个模型
export default DS.Model.extend({
fullName: DS.attr('String'),
form: DS.attr('String'),
leader: DS.belongsTo('contact', { async: true })
}
和联系模式:
export default DS.Model.extend({
fullName: DS.attr('String'),
email: DS.attr('String')
});
答案 0 :(得分:5)
您应该使用store.pushPayload
代替,因为该记录已存在于后端:
createObject() {
$.getJSON('http://localhost:8080/object/getCard?id=24').then((response) => {
this.store.pushPayload(response);
});
}