我将一个数据对象传递给一个带有铁路由器的模板,但希望访问 Template.name.rendered = function() { ... } 回调。
Template.name.rendered = function() { ... }
从…起 Meteor data-context with iron-router 我试过了 UI.getData() 但收到错误 There is no current view .使用 this.data 返回null。
UI.getData()
There is no current view
this.data
如何访问从呈现回调传递给模板的数据对象?
您在寻找数据上下文方面走上了正确的道路,但这实际上是您访问数据上下文的方式:
var ctx = Template.currentData();
而且,我相信 Template.x.rendered 即将被弃用,因此如果不起作用,请尝试使用
Template.x.rendered
Template.x.onRendered(function() { var ctx = Template.currentData(); console.log(ctx); });