I have very nested data, so I added a {{scope variable}}...{{/scope}}
tag, which does nothing but changing the scope:
scope: function (newScope) {
return this.tagCtx.render(newScope);
}
This works so far, but this sample code has an issue in the onAfterChange
, which I use to push data back to the server.
In the initializer:
data.Foo.Bar.TheObject = new MyObject('Foo'); // has "Name" property set to "Foo"
In the template:
{{scope Foo.Bar.TheObject}}
<input type="text" data-link="Name" />
{{/scope}}
It will display "Foo" correctly, but when I change it, in the onAfterChange
I get the data
object instead of TheObject
. Can I add something to {{scope}}
to achieve a scope change for the onAfterChange
?
(The {{for}}
tag has this behavior but I can't loop over a single object.)
As mentioned in comments above, the
{{for}}
tag does indeed cater to scenarios where you want to move the current data context (what mrs_sheep refers to as 'scope') to a different object (or array).You can do
{{for my.path.to.some.objectOrArray}}
- and the target does not have to be an array.See http://www.jsviews.com/#fortag "Render the specified template for the given object, or iterate over the given array"