问题
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