Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Access scope from the child can.Component event

$
0
0
Hi,

What is the idiomatic way in canjs of accessing the scope of a "child" can.Component which has its own template that is rendered inside the parent can.Component's template?

To clarify my question, please look at the following fiddle: http://jsfiddle.net/ry995zvh/10/:
  • If you look at the log displayed by {{log 'child scope'}}, you will see that the context inside {{#countries}}...{{/countries}} is an instance of the Country model, with the correct 'id' and 'name' properties.
  • If you look at the log line displayed by {{log 'child scope inside child template'}}, that context is not of type Country. Still, the rendering of the model instance by using "{{id}}" and "{{name}}" in the child template works fine: even if 'id' and 'name' properties are not in the current context, they are found upstream, in the parent scope. But I cannot access the Country model properties from the 'click' event from the child Component without using the 'country={.}' attribute. I would like to access the object of type Country from inside the click event of the child Component without the need to pass the Country instance scope by using an attribute of the country tag: <country country={.}></country> .
In other words, how can I access the instance of the Country model from inside the ' click ' event of the child can.Component without passing the attribute " country={.} " to the tag  <country> ?

Thank you!


Viewing all articles
Browse latest Browse all 3491

Trending Articles