FB.XFBML.parse() 在渲染过程中失败

FB.XFBML.parse() fails during rendering

我一直在尝试执行 FB.XFBML.parse(); 以重新加载所有 Facebook 社交插件。我可以在 Template.sample.events({}) 中成功执行它,但不能在 Template.sample.onRendered()Template.sample.rendered 中执行,因为我收到一条错误消息,指出 FB 未定义。我的代码如下:

Template.sample.onRendered(function() {
  FB.XFBML.parse();
});

Template.sample.rendered = function() {
  FB.XFBML.parse();
}

如何执行 FB.XFBML.parse();每次加载模板?

刚刚用 try-catch 块包装了该方法。注意到 for rendered 被多次调用。第一遍失败,说 FB 未定义,而后续的遍成功。

Template.sample.rendered = function() {
    try {
        FB.XFBML.parse();
    } catch (e) {
        // Will normally crash but succeeding execution will be successful
    }
}