Can i get the template parent data context in the event function?

我与影子孤独终老i 提交于 2020-01-05 07:46:30

问题


I'd love to get my hands on a templates data context. Can I do something like this?

'click .newContext': function(event, template) {
    var template_parent = template.parent();
    var parent_data = template_parent.data;
}

回答1:


You can use Template.parentData(0), the argument defines how deep you want to go, if you pass none, 0 is the default. Check the documentation on this: http://docs.meteor.com/#/full/template_currentdata




回答2:


Yeah, if you're trying to get the parent's data context you should be able to use the parentData() method on the Template instance. You probably don't even need that second template parameter.

'click .newContext': function(event) {
    var parent_data = Template.parentData();
}


来源:https://stackoverflow.com/questions/26956647/can-i-get-the-template-parent-data-context-in-the-event-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!