对于一个简单的消息传递应用程序,我有以下数据结构:
App.Message = DS.Model.extend({
title: DS.attr("string"),
body: DS.attr("string"),
isRead: DS.attr("boolean"),
replyTo: DS.belongsTo("App.Message")
});
App.Message.FIXTURES = [{
id: "1",
title: "Eos ut amet persius, ea ius nibh iudico",
body: "Lorem ipsum dolor sit amet, nam et hinc doctus alienum, in vel latine conceptam.",
isRead: true,
replyTo: null
},
{
id: "2",
title: "Ad est dolor veniam delenit.",
body: "Lorem ipsum dolor sit amet, nam et hinc doctus alienum, in vel latine conceptam.",
isRead: false,
replyTo: "1"
},
{
id: "3",
title: "Eu nec summo placerat reprehendunt.",
body: "Lorem ipsum dolor sit amet, nam et hinc doctus alienum, in vel latine conceptam. Tale eirmod omittantur sit ne. Minim noster philosophia per eu, mel putent veritus an, ex veniam ubique consulatu has. At stet diceret repudiare ius, probo liber diceret no est. Ridens efficiantur vim te.",
isRead: false,
replyTo: "1"
}];
我试图在选择消息时显示对消息的回复,但没有出现。 消息主题和正文显示正常,因此我知道我的路由、控制器和模板至少已为父实体正确设置。
这是我的模板(为简洁起见,几乎删除了所有标记):
<script type="text/x-handlebars" data-template-name="message">
<h2>{{ title }}</h2>
<p>{{ body }}</p>
{{ render "messageResponses" responses }}
</script>
<script type="text/x-handlebars" data-template-name="messageResponses">
{{#each responses}}
<p>{{ body }}</p>
{{/each}}
</script>
还有我的消息控制器(我可能做错的部分):
App.MessageController = Ember.ObjectController.extend({
responses: function() {
return App.Message.find({ replyTo: this.get("id") );
}
});