Making a template helper reactive in Meteor

后端 未结 5 779
刺人心
刺人心 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:46

    To mimick the behaviour of Session without polluting the Session, use a ReactiveVar:

     Template.contactsLayout.created = function() {
          this.data.newChatters = new ReactiveVar([]);
     }
    
     Template.contactsLayout.events({
          'click #contactItem': function (event, template) {
                ...
                template.data.newChatters.set(
                    template.data.newChatters.get().push(this.username)
                );
               ...
    

    Then, in the inner template, use the parent reactive data source:

     Template.newChatDetails.helpers({
          newChatters: function() {
               return Template.parentData(1).newChatters.get();
          }
     });
    

提交回复
热议问题