新手 Ember 用户 - 在模板中的条件语句内的每个循环中显示内容时遇到问题。如果没有条件,内容将被很好地列出。
我有以下模板:
<script type="text/x-handlebars" data-template-name="application">
{{view "App.MenuView" }}
</script>
<script type="text/x-handlebars" data-template-name="menu">
<div class="app-navbar">
<ul class="app-nav">
{{#link-to 'applications' tagName="li" href=false }}<a {{action "select_application" on="click"}} href="#nogo">Applications <b class="caret"></b></a>
{{#if showApplications}}
<ul class="app-subnav">
{{#each view.content1}}
<li ><a href="#" {{action "select" this}}>{{title}}</a></li>
{{/each}}
</ul>
{{/if}}
{{/link-to}}
</script>
这是我的视图和控制器:
App.MenuView = Ember.View.extend({
templateName: 'menu',
content1:[
Ember.Object.create({title: 'google', href: 'google.com'}),
Ember.Object.create({title: 'yahoo', href: 'yahoo.com'}),
Ember.Object.create({title: 'bing', href: 'bing.com'})
]
})
App.ApplicationController = Ember.ObjectController.extend({
isActive : false,
showApplications: false,
actions:{
select_application : function(e){
this.toggleProperty('isActive');
this.toggleProperty('showApplications');
}
select: function(e){
console.log ('Do something here');
}
}
})