我正在尝试学习ember.js,我在尝试将DS.FixtureAdapter
与模拟数据一起使用时遇到了问题。每当我尝试访问商店时,我都会收到Ember错误:
处理路径时出错:练习断言失败:Ember数据需要一个数字或字符串来表示pictureExercises
关系中的记录,而不是找到一个对象。如果这是多态关系,请指定type
密钥。如果这是嵌入式关系,请添加DS.EmbeddedRecordsMixin*
并在序列化程序的attrs哈希中指定pictureExercises
属性。
查看ember检查器中的余烬数据部分,我可以看到所有顶级练习数据都已正确加载,而PictureExercises和VideoExercises则没有。
如何在Ember.js中声明多态关系的type
键?
我完全失去了任何帮助,我们将不胜感激。 感谢您的时间。
//Create application store
Gymbo.ApplicationAdapter = DS.FixtureAdapter;
//Set up models and relationships
Gymbo.Exercise = DS.Model.extend({
//id: DS.attr("number"), /*Ember will error if id is in model* /
name: DS.attr("string"),
description: DS.attr("string"),
pictureExercises: DS.hasMany("pictureExercise", {async: true }),
videoExercises: DS.hasMany("videoExercise", { async: true })
});
Gymbo.PictureExercise = DS.Model.extend({
//id: DS.attr("number"),
exerciseId: DS.attr("number"),
mimeType: DS.attr("string"),
picFilePath: DS.attr("string"),
picName: DS.attr("string"),
exercise: DS.belongsTo("exercise")
});
Gymbo.VideoExercise = DS.Model.extend({
//id: DS.attr("number"),
exerciseId: DS.attr("number"),
videoName: DS.attr("string"),
videoFilePath: DS.attr("string"),
videoType: DS.attr("string"),
exercise: DS.belongsTo("exercise")
});
//UsersRoute
Gymbo.ExercisesRoute = Ember.Route.extend({
model: function () {
return this.store.find("exercise");
}
});
//MOCK DATA
Gymbo.Exercise.reopenClass({
FIXTURES:
[
{
"id": 101,
"name": "Exercise 1",
"description": "Description here",
"pictureExercises": [
{
"id": 106,
"exerciseId": 101,
"mimeType": "PNG",
"picFilePath": "images\\strength",
"picName": "s001"
},
{
"id": 107,
"exerciseId": 101,
"mimeType": "JPG",
"picFilePath": "images\\strength",
"picName": s002
}
],
"videoExercises": [
{
"id": 101,
"exerciseId": 101,
"videoName": "Test",
"videoFilePath": "Video\\strength",
"videoType": "mp4"
}
]
},
{
"id": 102,
//Data removed for brevity.....
}
]
});