Emberjs:{{#view}}帮助器中的classBinding的上下文是什么? [英] Emberjs:what's the context the classBinding on {{#view}} helper use?

查看:91
本文介绍了Emberjs:{{#view}}帮助器中的classBinding的上下文是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

doc 的示例意味着上下文实例查看而没有控制器。但是我不能用最新版本来尝试这一点,请查看这个jsfiddle的链接

The doc's example implies that the context is the instance of a View without a controller. But I can't try this out with latest version, please check this jsfiddle's link.

推荐答案

这是我做的方式: http://jsfiddle.net/arasbm/ACqjt/1/

只是为了澄清视图的上下文设置为它的控制器默认。如果要在视图模板中访问视图属性,例如 flag ,您将使用 view.flag 来引用

Just to clarify context of the view is set to it's controller by default. If you want to access a property of view such as flag inside the view template you would use view.flag to refer to it.

我喜欢在视图本身内设置视图类名称绑定:

I prefer to setup view class name bindings inside the view itself:

classNameBindings: ['flag:A:B']

你也应该能够在模板中做绑定,但我不知道为什么这不是在你的小提琴。在您定义视图时不要使用引号,而应使用:

You should also be able to do the binding in the template, but I am not sure why that is not working in your fiddle. Do not use quotations when you are defining your view, instead use:

{{view App.CustomDiv}}

{{#view App.CustomDiv}}{{/view}}

如果你不想使用一个单独的模板为您的视图。我喜欢为每个视图设置一个模板。我将它们放在单独的文件中,例如 custom.handlebars ,但是对于jsFiddle中的演示,您可以使用数据模板名称属性来命名要使用的模板,然后使用 templateName 在视图定义中引用它。我希望这有助于你前进。

if you dont want to use a seperate template for your view. I like to setup a template for each view I have. I put them in separate files for example custom.handlebars, but for demonstration in jsFiddle you can use the data-template-name property to name the template you want to use, and then refer to it inside the view definition using templateName. I hope this helps you move forward.

这篇关于Emberjs:{{#view}}帮助器中的classBinding的上下文是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆