Meteor Reactive Table onchange fields 事件

Meteor Reactive Table onchange fields event

我找不到关于在 Reactive 上使用 onchange 事件的任何问题或答案 Table。

每当我按下 table 上的任何行并记录该行上的值时,我都可以 console.log 单击事件。 但是只要其中一个字段值发生变化,我就无法记录。可能是我的语法有误,我只是想不通以及如何让它工作。

这是我的代码:

tables.js

Template.tables.onCreated( function() {
   this.subscribe('adverts');
   var currentPage = new ReactiveVar(Session.get('current-page') || 0);
   this.currentPage = currentPage;
   this.autorun(function () {
      Session.set('current-page', currentPage.get());
      console.log(currentPage)
     });
   });

    Template.tables.helpers({
       table: function() {
            return Adverts.find().fetch();
        },
 })
    Template.tables.events({
    'onchange .reactive-table tbody tr': function () {
        var fields = this;
        Session.set('post', fields);
        console.log(fields)
      },
    })

tables.html

<template name="tables">
 <div>
    {{> reactiveTable showFilter=false showNavigation='never' collection=table}}
 </div>
</template>

tr 个元素无法触发 change 个事件。您正在寻找数据更改而不是用户交互,因此处理此问题的更好方法是使用观察者:

var cursor = Adverts.find();
var handle = cursor.observe({
    changed: function(newDocument, oldDocument) {
        //handle change
    }
});

有关观察者的更多信息,请参阅 docs