问题
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