Ember.js 我可以访问{{#with}}范围内的视图属性吗?
我想根据视图属性的值,在{{#with}}}范围内切换元素的可见性。 我可以在{{#with}中访问{{action}中的查看属性,但无法在{#with}中访问查看属性 下面是一个示例程序Ember.js 我可以访问{{#with}}范围内的视图属性吗?,ember.js,Ember.js,我想根据视图属性的值,在{{#with}}}范围内切换元素的可见性。 我可以在{{#with}中访问{{action}中的查看属性,但无法在{#with}中访问查看属性 下面是一个示例程序 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script> <script>!window.jQuery && document.write(
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script>!window.jQuery && document.write(unescape('%3Cscript src="js/libs/jquery-1.6.1.min.js"%3E%3C/script%3E'))</script>
<script src="http://cloud.github.com/downloads/emberjs/ember.js/ember-0.9.5.js"></script>
<script type="text/javascript">
var App = Em.Application.create();
App.Test = Em.View.extend({
content: {
description: 'names',
names: [{name: 'bob'}, {name: 'john'}]
},
viewDetail: false,
toggleDetail: function() {
this.set('viewDetail', true);
}
})
</script>
<script type="text/x-handlebars">
{{#view App.Test}}
{{#with content}}
{{description}}<br/>
{{#each names}}
{{name}}
{{/each}}
<br/>
<button {{action toggleDetail}}>toggle Detail</button> <!-- can access toggleDetail -->
{{#if viewDetail}} <!-- but can not access viewDetail... -->
…detail Description...
{{/if}}
{{/with}}
{{/view}}
</script>
!window.jQuery&&document.write(unescape(“%3Cscript src=”js/libs/jQuery-1.6.1.min.js”%3E%3C/script%3E'))
var App=Em.Application.create();
App.Test=Em.View.extend({
内容:{
描述:'名称',
姓名:[{name:'bob'},{name:'john'}]
},
viewDetail:false,
toggleDetail:function(){
此.set('viewDetail',true);
}
})
{{{#查看App.Test}
{{{有内容}
{{description}}
{{{#每个名字}
{{name}}
{{/每个}}
切换细节
{{#如果查看详细信息}
…详细说明。。。
{{/if}
{{/与}}
{{/view}
我是否可以访问{{{with}}范围中的查看属性?{with
修改把手上下文。您可以使用。/
返回一个级别
尝试一下:
{{#if ../viewDetail}}
你知道如何在{{{if}}块中返回一个级别吗?@Fadi,你只需要在属性前面加上
内容。
或添加一个新的块。