我有以下资源
API用于通过父对象ID传递子对象,我看不到与开箱即用的Ember数据兼容(或者没有黑客攻击,只有正确的配置)。
问题资源让我获得JSON:
{
"errors": [],
"data": {
"created": 1439832769693,
"updated": 1440012378723,
"userID": 20,
"user": {
"password": null,
"created": null,
"updated": null,
"photoID": null,
"photo": null,
"email": "notsoimportant@host.com",
"emailConfirmed": false,
"phoneNumber": null,
"phoneNumberConfirmed": false,
"accessFailedCount": 0,
"id": 20,
"userName": "qwerty"
},
"categories": [], // does not exist in json
"addCategoriesIDs": [],
"removeCategoriesIDs": [],
"recommendations": [],
"removeRecommendstionIDs": [],
"patternAnswers": [],
"removePatternAnswerIDs": [],
"comments": [], //does not exist in json
"hint": null,
"version": 1,
"commonVersion": 8,
"id": 7,
"questionText": "What is your name?",
"weight": 0,
"answerType": 0,
"status": 0,
"estimatedTime": null,
"private": false
}
}
属性“patternAnswers”,“推荐”在问题中,但“评论”和“类别”不是。 更多我没有得到列出的属性填充了依赖对象的ID的问题。我希望我能得到
{
"errors": [],
"data": {
"comments" : [11,12,13,14],
"categories" : [21,22,23,24],
"recommendations": [1,2,3,4],
"removeRecommendstionIDs": [],
"patternAnswers": [5,6,7,8],
"removePatternAnswerIDs": [],
"hint": null,
"version": 1,
"commonVersion": 8,
"id": 7,
....
}
}
..但它们是空的:(
我想配置我的问题模型和问题序列化器以异步方式获取所有依赖对象。
我想发布一切只是发布
var QuestionModel = this.store.find('question',7);
var comments = QuestionModel.get('comments');
var categories= QuestionModel.get('categories');
var recommendations= QuestionModel.get('recommendations');
var patternAnswers= QuestionModel.get('patternAnswers');
怎么可行?
答案 0 :(得分:1)
如果您希望此功能开箱即用,则应根据余烬指南(http://guides.emberjs.com/v2.0.0/models/the-rest-adapter/)设置API。也就是说,端点必须是:
来自GET / api / v1 / questions / {questionID}的有效负载应如下所示:
DS.Model
否则,您需要更改RESTAdapter
或/和QuestionController
的默认行为,或使用model
附加的类别,评论等模型。或者您可以打包所有内容在路由的setupController
和/api/v1/questions/{questionID}
挂钩中表示该数据。
我建议你自己回答这些问题:
更改API可以走多远?还有另一种类似的方案:
问题/api/v1/questions/{questionID}/categories/{categoryID}
类别/api/v1/questions/{questionID}/categories
分类<exclude-unlisted-classes>true</exclude-unlisted-classes>
在Ember和你的版本中配置起来要容易一些。