我通过以下方式实现了解决方案。请让我知道我的代码中的任何缺点。在调用入口路由以使其可见时,我正在为入口模型设置一个属性。
HTML:
<script type="text/x-handlebars" >
{{outlet}}
</script>
<script type="text/x-handlebars" id="entries">
{{#each controller }}
{{#linkTo "entry" this}}{{name}}{{/linkTo}} <br />
{{#if visi}}
<p>{{details}}</p>
{{/if}}
{{/each}}
</script>
JAVASCRIPT:
App = Ember.Application.create();
App.Router.map(function(){
this.resource('entries', { path: '/'}, function() {
this.resource('entry', { path: 'entry/:entry_id' });
});
});
App.Entry = Em.Object.extend({
id: null,
name: null,
details: null
});
App.entries =[
App.Entry.create({
id: 1,
name: 'entry 1',
details: 'details 1'
}),
App.Entry.create({
id: 2,
name: 'entry 2',
details: 'details 2'
}),
App.Entry.create({
id: 3,
name: 'entry 3',
details: 'details 3'
})
];
App.EntriesRoute=Ember.Route.extend({
model:function() {
return App.entries;
}
});
App.EntryRoute=Ember.Route.extend({
model:function(params) {
var id=parseInt(params.entry_id);
return App.entries.findProperty('id',id);
},
setupController:function(controller,model){
App.entries.setEach('visi',false);
model.set('visi',true);
}
});
问候。