Emberjs:{{#view}}助手上的classBinding使用什么上下文? [英] Emberjs: what's the context the classBinding on {{#view}} helper use?

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

问题描述

doc 的示例暗示context是没有controllerViewinstance.但我无法使用最新版本进行尝试,请检查此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.

推荐答案

这是我执行此操作的方法:

Here is the way I would do this: 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中进行演示,您可以使用data-template-name属性命名要使用的模板,然后使用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天全站免登陆