3
我想根据视图属性的值在{{#with}}范围内切换元素的可见性。 我可以在{{#with}}中的{{action}}中查看属性,但我无法访问{{with}中的属性。我可以在{{#with}}范围内访问视图属性吗?
下面是一个示例程序。
<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>
我可以在{{#with}}范围内查看属性吗?
可以访问!谢谢! – arumons 2012-03-05 12:46:40
你碰巧知道如何在{{#if}}块中恢复关卡? – Fadi 2012-03-30 18:51:12
@Fadi,你只需在content.'前添加属性或者添加一个新的'with'块。 – 2012-03-30 18:53:55