从ContentBinding获取内容

编程入门 行业动态 更新时间:2024-10-14 18:13:04
本文介绍了从ContentBinding获取内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有新的Ember.js(1.0 pre)的问题

我得到了一些有用的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获取内容

本文发布于:2023-11-25 23:08:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1631717.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:内容   ContentBinding

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!