首页 文章

带有反应表的meteor livestamp

提问于
浏览
0

我有一个使用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 的功能?

2 回答

  • 0

    你可以用https://atmospherejs.com/aldeed/tabular它's also datatables but it'的不同包(在我看来更好)

    如果您选择使用它是一个示例,表格可以选择将字段呈现为模板,而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>
    
  • 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>
    

相关问题