【问题标题】:Pass param to object's method in Blaze template将参数传递给 Blaze 模板中的对象方法
【发布时间】:2015-04-24 20:39:51
【问题描述】:

我想做这样的事情:

Template.main.helpers({
  item: function() {
    return {
      title: 'Title',
      method: function(param) {
        return param.toUpperCase();
      }
    }
  }
});

和模板:

<template name="main">
  <div>{{item.title}}</div>
  <div>{{item.method "some text to upper case"}}</div>
</template>

不幸的是,我收到错误 Can't call non-function: undefined。很奇怪,我可以调用对象的方法一切正常,但是当我尝试将参数传递给它时,它会抛出错误。

当然,我可以创建一些帮助程序来获取我的对象并使用参数调用方法,但这是一种丑陋的解决方法。有没有办法将参数传递给对象的方法?

【问题讨论】:

    标签: templates meteor meteor-blaze


    【解决方案1】:

    您是否尝试过使用单引号?

    <template name="main">
      <div>{{item.title}}</div>
      <div>{{item.method 'some text to upper case'}}</div>
    </template>
    

    Tbh,我从未尝试过将对象与助手一起使用。有趣的想法虽然:P

    【讨论】:

      猜你喜欢
      • 2015-09-22
      • 2019-08-30
      • 1970-01-01
      • 2010-12-12
      • 2011-05-28
      • 2015-09-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多