我有以下的ember请求
this.store.createRecord('food_list',requestObj
).save().then((response) => {
console.log(response);
console.log(response.id); // This is working
console.log(response.food_list_code); //this does NOT work !!!!!
}
它将调用API并将记录保存到数据库,然后返回以下响应。
{
"links": {
"self": "/api/food_list"
},
"data": {
"type": "",
"id": "da6b8615-3f4334-550544442",
"attributes": {
"food_list_date": "2013-02-14 23:35:19",
"food_list_id": "da6b8615-3f4334-550544442",
"food_list_code": "GORMA",
},
"relationships": {
"food_list_parameters": {
"data": [
{
"type": "food_list_parameter",
"id": "RERAFFASD9ASD09ASDFA0SDFASD"
}
]
},
"food_new_Name": {
"data": {
"type": "food_new_Name",
"id": "AKASDJFALSKDFKLSDF23W32KJ2L23"
}
}
},
"links": {
"self": "/api/BLAH/BLAH/BLAH"
}
}
}
但由于上面的响应是一个ember对象形式的JSONAPI,我不知道如何解析它。 如果我尝试获取response.id,我会得到字符串da6b8615-3f4334-550544442
但是如何在响应块中获取food_list_code的值。或者如何迭代响应对象以获得" food_list_code"和" food_list_date" ?
console.log(响应)的输出如下面的ember类
Class {__ember1500143184544: "ember1198", store: Class, _internalModel: InternalModel, currentState...
感谢您的帮助。 微米。