【问题标题】:How can I do something like this in a template?: {{userScores.{{currentUserId}}.[0].score}}我怎样才能在模板中做这样的事情?:{{userScores.{{currentUserId}}.[0].score}}
【发布时间】:2017-03-25 02:03:12
【问题描述】:

这对我有用,但它是硬编码的: {{userScores.KxXJYDLvCvjk9nLwo.[0].score}}

我想用 Meteor.userId() 代替硬编码的 id。

我该怎么做?

当然,这是行不通的; {{userScores.Meteor.userId().[0].score}}

【问题讨论】:

    标签: meteor meteor-blaze spacebars


    【解决方案1】:

    您不能直接在 Blaze 中执行此操作,您需要一个助手,例如:

    {{score0}}
    

    js:

    Template.myTemplate.helpers({
      score0() {
        return this.userScores[Meteor.userId()][0].score;
      }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-06
      • 2022-01-12
      • 1970-01-01
      • 1970-01-01
      • 2012-04-02
      • 2011-08-20
      • 2019-07-12
      相关资源
      最近更新 更多