Updating template with session variable and subscription/publication only updates with previous query and appends information

后端 未结 1 2023
清歌不尽
清歌不尽 2021-01-21 22:08

How it works

I have a subscript/publication set up for a Videos Collection (pretty much a list of video information) and a Specs Collection (a list of informa

相关标签:
1条回答
  • 2021-01-21 22:53

    I saw in my projects that, when subscribing/calling something on meteor, sometimes it run next code lines without having received previews server answer, and it bring some problems like yours. So, I usually nest what should be done inside the subscribe/call function, then it is run only after data is returned.

    I would do something like this:

    Template.List.events({
        'change #categories':function(evt){
    
             Meteor.subscribe("videos-pub-sub", $(evt.target).val(), function(){
                   //to empty the table
                   $('#video_table').find('tbody').empty();
                   var vids = Videos.find({}).fetch();
                   Session.set("videos-session", Videos.find({}).fetch());
             });
    
         }
    });
    

    Let me know if it works!

    0 讨论(0)
提交回复
热议问题