代码之家  ›  专栏  ›  技术社区  ›  user1560249

渲染回调中的iron路由器模板数据

  •  1
  • user1560249  · 技术社区  · 10 年前

    我将一个数据对象传递给一个带有铁路由器的模板,但希望访问 Template.name.rendered = function() { ... } 回调。

    从…起 Meteor data-context with iron-router 我试过了 UI.getData() 但收到错误 There is no current view .使用 this.data 返回null。

    如何访问从呈现回调传递给模板的数据对象?

    1 回复  |  直到 8 年前
        1
  •  1
  •   John Smith    10 年前

    您在寻找数据上下文方面走上了正确的道路,但这实际上是您访问数据上下文的方式:

    var ctx = Template.currentData();
    

    而且,我相信 Template.x.rendered 即将被弃用,因此如果不起作用,请尝试使用

    Template.x.onRendered(function() { 
      var ctx = Template.currentData();
      console.log(ctx);
    });
    
    推荐文章