Client data not getting refreshed after subsequent submit event


#1

I am publishing data at server and subscribing it at client. For the first time data at the client is displayed but for subsequent events i have to refresh the page for displaying the new data otherwise its displaying the previous data. Its not a synchronization issue as i am using autorun. Below is the code: I can see for each sumit event server is sending the correct data to the client but the client is displaying the older data until page is refreshed. the minimongo is also displaying the previous data. when i used console.log(Counts.find()) its displaying the correct number of records for the new data set fetched. But when i used console.log(Collection_name.find().count()) it displays the number of records of the previous dataset.
Below is my code:

var pageSession = new ReactiveDict();
var location = new ReactiveVar("");
var profession = new ReactiveVar("");
var hospital = new ReactiveVar("");

Template.adssearchResultsTable.onCreated(function searchResultsSearchBoxOnCreated() {
var instance = this;
instance.autorun(function() {
pageSession.set(“ready”,"");
var sub1 = instance.subscribe(‘adv_search’,location(),profession(),hospital(),0);
if(sub1.ready()){
pageSession.set(“ready”,“ready”);
}
});
});

Template.adssearchResultsTable.events({
“submit .SearchBox”: function(e, t) {
e.preventDefault();

pageSession.set("SearchResultsSearchBoxInfoMessage", "");
pageSession.set("SearchResultsSearchBoxErrorMessage", "");
    var locat = $("#location").val();
    var prof = $("#profession").val();
    var hosp = $("#hospitals").val();
    FlowRouter.go("/advanceSearch/:searchType",{searchType:"Advance"},{location:locat,profession:prof,hospital:hosp});

}
});

Template.adssearchResultsTable.helpers({

"adstableItems": function() {
    console.log(Joblist.find({}, {}).count());
    return Joblist.find({}, {});
});

#2

You have missed some syntax especially around the autorun, where your ReactiveVars are being referenced. I’ve also taken the liberty of moving your reactive data into the template instance, where they are being used. (I probably overstepped the mark, there, so feel free to ignore if not appropriate :slight_smile:)

Template.adssearchResultsTable.onCreated(function searchResultsSearchBoxOnCreated() {
  this.pageSession = new ReactiveDict();
  this.location = new ReactiveVar('');
  this.profession = new ReactiveVar('');
  this.hospital = new ReactiveVar('');
  this.autorun(() => {
    this.pageSession.set('ready', '');
    const sub1 = instance.subscribe('adv_search', this.location.get(), this.profession.get(), this.hospital.get(), 0);
    if (sub1.ready()) {
      this.pageSession.set('ready', 'ready');
    }
  });
});

Template.adssearchResultsTable.events({
  'submit .SearchBox'(e, t) {
    e.preventDefault();

    t.pageSession.set('SearchResultsSearchBoxInfoMessage', '');
    t.pageSession.set('SearchResultsSearchBoxErrorMessage', '');
    const location = $('#location').val();
    const profession = $('#profession').val();
    const hospital = $('#hospitals').val();
    FlowRouter.go('/advanceSearch/:searchType', { searchType: 'Advance' }, { location, profession, hospital });
  },
});

Template.adssearchResultsTable.helpers({
  adstableItems() {
    console.log(Joblist.find({}, {}).count());
    return Joblist.find({}, {});
  },
});

#3

Hi Rob

Thanks for your reply. It still not working.
Actually on each submit event correct data is getting published each time at the server but its not getting updated at the client after first submit event. The minimongo is also displaying the old data i.e. data of first submit event.

I can see on the console its subscribing for each submit event and data getting published at server but don’t know why its not getting updated in minimongo.