我得到了一些有用的Ember 0.9.8,但是当我更改这个lib的版本我注意到无法解决的问题。 (我不太在Ember:/)
这里是示例代码: jsfiddle/ETQCc/5/
我创建视图:
< script type =text / x-handlebarsdata-template-name =MyView> {{s}} / {{content.s}} / {{this.s}} / {{view.s}} < / script> App.myview = Em.View.extend({ layoutName:MyView,});我想显示一些可变的,这取决于我在内容中设置的bindig: p>
< script type =text / x-handlebars> xx {{view App.myview contentBinding =App.ctrl}} < / script>如何在此控制器中获得变量?
解决方案你有两种方法可以做到这一点。 您可以:
- 将控制器绑定到视图,而不是绑定内容(请参阅 JSFiddle )。通过这样做,您将视图的上下文设置为控制器,因此 {{s}} 直接工作:
{{view App.myview controllerBinding =App.ctrl}}
- 编辑您的模板以从视图而不是其上下文获取变量(请参阅这个JSFiddle )。通过这样做,视图内容被绑定到控制器,您的模板显示视图内容的 s 属性:
{{view.content.s}}
我建议你以查看 Ember.js查看上下文更改。
I've got problem with new Ember.js (1.0 pre)
I got something what worked on Ember 0.9.8 but when I changed version of this lib I noticed problem which can't resolve. (I'm not so good at Ember :/)
Here is sample code: jsfiddle/ETQCc/5/
I created view:
<script type="text/x-handlebars" data-template-name="MyView"> {{s}} / {{content.s}} / {{this.s}} / {{view.s}} </script> App.myview = Em.View.extend({ layoutName : "MyView", });And I'd like to show some varible which depends on what I set in content bindig:
<script type="text/x-handlebars"> xx{{view App.myview contentBinding="App.ctrl"}} </script>How to get to varible in this controller?
解决方案You have two ways to do that. You can :
- bind the controller to your view instead of binding the content (see the JSFiddle). By doing that you set the context of the view to be the controller, so {{s}} works directly:
{{view App.myview controllerBinding="App.ctrl"}}
- edit your template to get the variable from the view instead of its context (see this JSFiddle). By doing that the view content is binded to the controller, and your template shows the s property of the view content:
{{view.content.s}}
I suggest you to take a look at Ember.js View Context changes.
更多推荐
从ContentBinding获取内容
发布评论