0

我有一个使用livestamp的流星应用程序。但是,我希望在反应表中表示一个集合。但是,当我尝试下面的代码时,它不起作用(我在更新的列中看不到任何内容):

Template.sensor_table.helpers
  settings: () ->
    return {
      collection: Sensors
      rowsPerPage: 100
      showFilter: true
      fields: [ 
        { key: '_id', label: 'id' },
        { key: '_id', label: 'rack', fn: (v,o) -> (getSensor v).rack },
        { key: 'temp', label: 'temperature (degC)' },
        { key: 'ts', label: 'updated', fn: (v,o) -> livestamp v }
      ]
    }

但是当我在模板中使用它时,它工作正常。如何livestamp在我的反应表中获得功能?

4

2 回答 2

0

您可以使用https://atmospherejs.com/aldeed/tabular做到这一点,它也是数据表,但它是不同的包(我认为更好)

如果您选择使用它,这里是一个示例,表格可以选择将字段呈现为模板,并且 livestamp 应该像在模板本身上一样工作。

TabularTables.Books = new Tabular.Table({
  name: "Books",
  collection: Books,
  columns: [
    {data: "_id", title: "id"},
    {data: "_id", title: "Rack"},
    { data: 'ts', title: 'updated',
      tmpl: Meteor.isClient && Template.liveStamp
    }
  ]
});

// template
<template name="liveStamp">
  <p>{{livestamp this.ts}}</p>
</template>
于 2015-09-19T10:16:46.020 回答
0

所以我想它有助于实际阅读手册....

Template.sensor_table.helpers
  settings: () ->
    return {
      collection: Sensors
      rowsPerPage: 100
      showFilter: true
      fields: [ 
        { key: '_id', label: 'id' },
        { key: '_id', label: 'rack', fn: (v,o) -> (getSensor v).rack },
        { key: 'temp', label: 'temperature (°C)' },
        { key: 'ts', label: 'updated', tmpl: Template.sensor_updated }
      ]
    }

然后是某个地方的模板......

<template name="sensor_updated">
{{ livestamp ts }}
</template>
于 2015-09-23T08:46:11.017 回答