[英]How to access parent data in JsViews data-linked method
Is it possible to access parent data from within a data-linked function in JsViews? 是否可以从JsViews中的数据链接函数中访问父数据?
{^{for sections}}
...
{^{for itemTypes}}
<tbody>
<tr>
<td>{^{:label}}</td>
<td>{^{if addable==true}}<button class="btn btn-sm btn-primary" data-link="{on ~addItem}">Add an item</button>{{/if}} </td>
</tr>
</tbody>
{{/for}}
...
{{/for}}
Is it possible to access the section data (the parent) from the addItem function? 是否可以通过addItem函数访问节数据(父级)?
addItem: function(ev, eventArgs) {
var view = eventArgs.view;
var index = view.getIndex();
var parent = ????
...
}
Thanks 谢谢
The docs provide relevant information in a few places, such as: 该文档在几个地方提供了相关信息,例如:
For programmatic access within the addItem method, you can use view APIs to step up through the view hierarchy, then get the data: 对于addItem方法中的编程访问,可以使用视图API逐步浏览视图层次结构,然后获取数据:
var section = view.parent.parent.data;
or 要么
var section = view.parent.get("item").data;
Alternatively you can pass the section data down declaratively as a contextual parameter: 另外,您也可以将段数据声明为上下文参数:
{^{for itemTypes ~section=#data}}
...
<button ... data-link="{on ~addItem ~section}">
then use it directly: 然后直接使用它:
addItem: function(section, ev, eventArgs) {
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.