【问题标题】:In Meteor, Is there a way to use multiple helpers even if one can handle multiple arguments?在 Meteor 中,有没有办法使用多个助手,即使一个可以处理多个参数?
【发布时间】:2014-09-11 08:06:42
【问题描述】:

在我的流星项目中,我有多个助手。 helper1 可以处理多个参数,但即使只有一个参数他也很好。问题是我想将此处理程序与另一个处理程序 (helper2) 的结果链接起来,该处理程序也需要一个参数(实际的用户数据)。所以我写了以下内容:

{{helper1 helper2 currentUser}}

问题在于helper1 似乎有两个参数:helper2 的结果和currentUser,这意味着helper2 没有得到currentHelper 参数。

我尝试使用括号,这样每个人都可以得到自己的论点,就像这样:

{{helper1 helper2(currentUser)}}{{helper1 (helper2 currentUser)}}

甚至是括号:

{{helper1 {{helper2 currentUser}}}}

但是所有这些变通方法都出现语法错误。有什么可行的方法吗?

【问题讨论】:

标签: meteor meteor-blaze spacebars


【解决方案1】:

我终于找到了解决这个问题的方法——使用#with

{{#with firstHelper data}}
  {{secondHelper this}}
{{/with}}

【讨论】:

  • 请注意,如果firstHelper data 的结果是假的,则#with 块的内容永远不会被评估。
猜你喜欢
  • 2014-09-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多