简体   繁体   English

在jsViews中更改onAfterChange的范围

[英]Change the scope of onAfterChange in jsViews

I have very nested data, so I added a {{scope variable}}...{{/scope}} tag, which does nothing but changing the scope: 我有非常嵌套的数据,所以我添加了一个{{scope variable}}...{{/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. 到目前为止这是有效的,但是这个示例代码在onAfterChange有一个问题,我用它来将数据推送回服务器。

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 . 它会正确显示“富”,但是当我改变它,在onAfterChange我得到的data对象,而不是TheObject Can I add something to {{scope}} to achieve a scope change for the onAfterChange ? 我可以在{{scope}}添加一些内容来实现onAfterChange的范围更改吗?
(The {{for}} tag has this behavior but I can't loop over a single object.) {{for}}标记有此行为,但我无法遍历单个对象。)

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). 正如上面的评论中所提到的, {{for}}标记的确适合于您希望将当前数据上下文(mrs_sheep所指的“范围”)移动到其他对象(或数组)的情况。

You can do {{for my.path.to.some.objectOrArray}} - and the target does not have to be an array. 你可以{{for my.path.to.some.objectOrArray}} - 并且目标不必是一个数组。

See http://www.jsviews.com/#fortag "Render the specified template for the given object, or iterate over the given array" 请参阅http://www.jsviews.com/#fortag “为给定对象渲染指定的模板,或迭代给定的数组”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM