我得到以下模型:
一个名称,成员和版主(都是用户)的社区。拥有ID和名字的用户。Emberjs在带把手的模板中的条件输出
在CommunityMembers模板我想告诉所有的用户,如果该用户是一个主持人,我想添加一些额外的话说,他是一个主持人
<script type="text/x-handlebars" data-template-name="communityMembers">
//model contains an array of users in a community
{{#each user in model}}
<li>{{user.name}}</li>
{{#each moderator in controllers.community.moderators}}
//here is the problem-->
{{#if moderator.id == user.id}}
<b>this is a moderator</b>
{{/if}}
{{/each}}
{{/each}}
</script>
我知道,在车把上,你可以” t使用moderator.id == user.id,但它是一个简单的方式来说出我想要做什么。
我试图写一个把手帮手,但当我检查帮助者时,我的论点是我得到一个字符串说:“moderator.id”或“user.id”,所以没有工作。
我也试图与在我的社区对象的方法来做到这一点:在模板
App.Community = Ember.Object.extend({
isModerator: function(community, user_id){
return community.moderators.indexOf({"id":user_id})!=-1;
}
});
:
{{#if isModerator(controllers.community,user.id)}}
<h>this is a moderator</h>
{{/if}}
但是这给了我错误的模板,如:
. Compiler said: Error: Parse error on line 12: .../if}}
{{#if isModerator(controll
----------------------^ Expecting 'CLOSE', 'CLOSE_UNESCAPED', 'STRING', 'INTEGER', 'BOOLEAN', 'ID', 'DATA', 'SEP', got 'INVALID'
有没有人知道如何处理这个问题?