如何将JSON转换为存储对象? [英] How to convert JSON to store object?
本文介绍了如何将JSON转换为存储对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试过:
code> 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,
领导者:{
id:23,
fullName:testName test,
email:emailTest
}
}
我在Ember应用程序中有一个模型
导出默认DS.Model.extend({
fullName:DS.attr('String'),
form:DS.attr('String'),
领导者:DS.belongsTo('contact',{async:true})
}
和联系人模型:
导出默认DS.Model.extend({
fullName:DS.attr('String '),
电子邮件:DS.attr('String')
});
解决方案
您应该使用 store.pushPayload
,因为记录已经存在于后端:
createObject(){
$ .getJSON('http:// localhost:8080 / object / getCard? id = 24')然后((response)=> {
this.store.pushPayload(response);
});
}
I have a JSON object from my Spring backend. How do I create a data object in my Ember application store?
I tried:
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"
}
}
I have a model in Ember app
export default DS.Model.extend({
fullName: DS.attr('String'),
form: DS.attr('String'),
leader: DS.belongsTo('contact', { async: true })
}
And contact model:
export default DS.Model.extend({
fullName: DS.attr('String'),
email: DS.attr('String')
});
解决方案
You should use store.pushPayload
instead, since the record already exists in the backend:
createObject() {
$.getJSON('http://localhost:8080/object/getCard?id=24').then((response) => {
this.store.pushPayload(response);
});
}
这篇关于如何将JSON转换为存储对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文