Emberjs: what's the context the classBinding on {{#view}} helper use?

拟墨画扇 提交于 2019-12-10 23:52:59

问题


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.


回答1:


Here is the way I would do this: http://jsfiddle.net/arasbm/ACqjt/1/

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}}

or

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

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.



来源:https://stackoverflow.com/questions/14028086/emberjs-whats-the-context-the-classbinding-on-view-helper-use

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!