如何从控制台或其他JS代码调用Meteor模板助手?

Dan*_*scu 5 javascript meteor meteor-helper

我已经在Meteor中定义了一个模板助手

Template.postsList.helpers({
  filteredPosts: function getPosts() {
    return Posts.find(...);
  }
});
Run Code Online (Sandbox Code Playgroud)

如何从控制台调试该模板助手,以及如何从应用程序中的其他代码重用它?

Dan*_*scu 6

  1. 想要从应用程序的其他地方调用帮助程序,建议您将其分解为函数.

  2. 要快速调试帮助程序,请在客户端控制台中对此进行评估:

    Template.postsList.__helpers.get('filteredPosts')(...parameters);
    
    Run Code Online (Sandbox Code Playgroud)
  3. 有一个软件包可能有助于调试模板和模板助手:prasad19sara:client-debugger.