Making a template helper reactive in Meteor

后端 未结 5 776
刺人心
刺人心 2021-02-08 02:22

I am building a chat application and on my \"new chats\" page I have a list of contacts, which you can select one by one by tapping them (upon which I apply a CSS selected class

5条回答
  •  不思量自难忘°
    2021-02-08 02:23

    1) Define Tracker.Dependency in the same place where you define your object:

    var newChatters = [];
    var newChattersDep = new Tracker.Dependency();
    

    2) Use depend() before you read from the object:

    Template.newChatDetails.newChatters = function() {
      newChattersDep.depend();
      return newChatters;
    };
    

    3) Use changed() after you write:

    Template.contactsLayout.events({
      'click #contactItem': function(e, t) {
        ...
        newChatters.push(...);
        newChattersDep.changed();
      },
    });
    

提交回复
热议问题