[英]Rendering hasMany data in Ember.js
I have an app with a users
model as follows- 我有一个users
模型如下的应用程序-
App.User = DS.Model.extend({
name : DS.attr(),
email : DS.attr(),
comments : DS.hasMany('comment'),
});
App.User.FIXTURES = [{
id: 1,
name: 'Jane Smith',
email: 'janesmith@thesmiths.com',
comments: ["1", "2"]
}, {
id: 2,
name: 'John Dorian',
email: 'jd@sacredheart.com',
comments: ["1", "2"]
}
];
And a user
template to show details about an individual user as follows- 还有一个user
模板,用于显示有关单个用户的详细信息,如下所示:
<script type = "text/x-handlebars" id = "user">
<div class="user-profile">
{{#if deleteMode}}
<div class="confirm-box">
<h5>Really?</h5>
<button {{action "confirmDelete"}}> yes </button>
<button {{action "cancelDelete"}}> no </button>
</div>
{{/if}}
<h2>{{name}}</h2>
<span>{{email}}</span>
<ul>
{{#each user.comments}}
<li>{{user.comments}}</li>
{{/each}}
</ul>
<button {{action "edit"}}>Edit</button>
<button {{action "delete"}}>Delete</button>
</div>
{{outlet}}
</script>
My problem is that the user comments are not showing up on the page. 我的问题是用户评论未显示在页面上。 Can anyone tell me what I'm doing wrong, very new to Ember. 谁能告诉我我做错了什么,这对Ember来说很陌生。 Thanks. 谢谢。
Assuming 假设
App.Comment = DS.Model.extend({
comment : DS.attr(),
});
And you have fixture data for Comment 并且您具有夹具数据以供注释
The scope has changed, so this
inside your each is the comment 范围发生了变化,所以this
您的每个里面的评论
{{#each user.comments}}
<li>{{comment}}</li>
or
<li>{{this.comment}}</li>
{{/each}}
{{#each comment in user.comments}}
<li>{{comment.comment}}</li>
{{/each}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.