余烬装置和有许多关系
Ember fixtures and hasMany relations
由于某些原因,下面的代码产生Error while loading route: TypeError: Cannot read property 'typeKey' of undefined
。一切加载正常,直到我在注释装置中添加注释。我假设将注释嵌套在注释fixture中可以工作,因为这是API返回它的方式,但这似乎是断点。
**我应该注意到,我已经尝试将fixture添加到注释模型中,并使用note_id引用回注释。我没有得到一个错误,但我没有得到任何回复显示**
谢谢你的帮助。
模型/note.js
import DS from 'ember-data';
var Note = DS.Model.extend({
content: DS.attr('string'),
comments: DS.hasMany('comment'),
});
Note.reopenClass({
FIXTURES: [
{
id: 1,
content: 'This is the first comment',
comments: [
{ id: 1, content: 'First comment' },
{ id: 2, content: 'Second comment' },
{ id: 3, content: 'Third comment' }
]
},
{
id: 2,
content: 'This is the second comment',
comments: [
{ id: 4, content: 'First comment' },
{ id: 5, content: 'Second comment' },
{ id: 6, content: 'Third comment' }
]
}
]
});
export default Note;
模板/notes.hbs
{{#each}}
<div>
<div>{{content}}</div>
{{#each comments}}
{{this.content}}
{{/each}}
</div>
{{/each}}
模型/comment.js
import DS from 'ember-data';
var Comment = DS.Model.extend({
content: DS.attr('string'),
timestamp: DS.attr('date'),
note: DS.belongsTo('note')
});
Comment.reopenClass({
FIXTURES: [
{ id: 1, content: 'First comment', note_id: 1 },
{ id: 2, content: 'Second comment', note_id: 1 },
{ id: 3, content: 'Third comment', note_id: 1 }
]
});
export default Comment;
看起来我错过了一些东西。
需要async选项的关系设置为true
comments: DS.hasMany('comment', { async: true })
需要在父元素和子元素之间设置关系
Note.reopenClass({
FIXTURES: [
{
id: 1,
content: 'This is the first comment',
comments: [1, 2, 3]
},
{
id: 2,
content: 'This is the second comment',
comments: [4, 5, 6]
}
]
});
相关文章:
- 气质的“nestRemoting()”有时可以'找不到关系
- 如何在Parse中创建一对多关系
- 为什么在许多浏览器中drawImage()的性能略好于createPattern()
- Ext.js从json构建模型关系的问题
- JSDoc:模块和名称空间之间的关系是什么
- 单元测试依赖关系没有被嘲笑
- 在Nodejs中为许多用户处理计时器
- FRP 中 EventStreams 的循环依赖关系
- 有许多关系创建记录 - 为什么未定义
- Ember js - 更新其他表后,有许多关系中断
- 余烬.js有许多模型关系保存
- 对于具有一对多关系的主干模型,存储“;许多“;数组中的模型,而不是Collection
- Ember排序有许多关系
- 余烬装置和有许多关系
- 序列自引用有许多关系
- Ember.js如何扁平化async的许多关系
- 如何在父模型中添加新的许多关系
- Ember数据有许多关系空结果
- 在车把模板中显示具有许多余烬关系的第一项
- 如何在javascript中动态创建具有许多父级和子级关系的Json