【问题标题】:Ability to access specific values from helper in Meteor能够从 Meteor 中的助手访问特定值
【发布时间】:2016-04-21 14:12:37
【问题描述】:

在我的流星应用程序中,我想有选择地访问页面中的值。

if (Meteor.isClient) {

  var percentageData = [
    {
      percent_type : 'online',
      percentage: '20'
    },
    {
      percent_type : 'offline',
      percentage: '55'
    }
  ];

  Template.authenticated_user.helpers({
    percentInformation: percentageData
  })
}

在这里,我将一个简单的 JSON 返回到我的模板。

<template name="authenticated_user">

</template>

我想要的是能够将这个 JSON 的页面部分放在不同的地方。

例如:

&lt;div id = {{percentInformation[0].percent_type}}&gt;&lt;/div&gt; 将 id 分配给“在线”。

这可能吗?

【问题讨论】:

    标签: javascript json meteor


    【解决方案1】:

    这是可能的,唯一需要注意的是您也对数组成员使用点表示法:

    {{percentInformation.[0].percent_type}}
    

    【讨论】:

      猜你喜欢
      • 2015-01-29
      • 1970-01-01
      • 2016-03-04
      • 2013-06-18
      • 2015-03-28
      • 2014-09-26
      • 2016-06-10
      • 2014-05-12
      • 1970-01-01
      相关资源
      最近更新 更多