【问题标题】:meteor livestamp with reactive-table带有反应表的流星时间戳
【发布时间】:2017-08-16 01:43:47
【问题描述】:

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

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 的功能?

【问题讨论】:

    标签: meteor timestamp timeago


    【解决方案1】:

    您可以使用 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>
    

    【讨论】:

    • 感谢指向tabular 的指针,但我个人觉得reactive-table 更易于使用。
    【解决方案2】:

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

    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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-16
      • 2017-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多