4

无论如何要等待模板被渲染然后执行某些功能?

我试过之后,它不起作用。

Router.map(function () {
  this.route('post', {
    path: '/posts/:ll',

    action: function () {
      this.render('home');
    },

    after: function () {
      var n = this.params.ll
       UI.insert(UI.render(Template[n]), document.getElementById("child"))
    }
  });
});

原来子元素还不存在,因为在触发 after 函数时还没有渲染“home”模板。

非常感谢任何建议或解决方法。

4

2 回答 2

7

你能做这个吗:

action: function () {
  this.render('home');
  Template.home.rendered = function() {
    // ...
    Template.home.rendered = null;
  };
},
于 2013-12-29T09:37:38.903 回答
0

使用onAfterAction代替after

https://github.com/EventedMind/iron-router/blob/master/DOCS.md#before-and-after-hooks

于 2014-04-24T04:11:19.617 回答