Accessing template data DOM element in Jquery


#1

Hi,
I have a template helper that send the data from subscribed mongo db to the template.

Template.hello.helpers({
    list: function () {
		var results = (SomeData.findOne({_id: Session.get("uuid")})) ? SomeData.findOne({_id: Session.get("uuid")}).data : "";
		return results;
    }
});

Whenever the mongo record is updated through a API call the helper is triggered and it sends the new data to the template.

The template creates a table and populates the data from the helper (created a row for each record from the data).

I want to perform some Jquery operation on the table rows. But the issue that I am facing is that, the jquery is running even before the new data is getting populated inside the rendered template.

How I ensure that Jquery is running after the table is populated with the new data??

Thanks,
Rohit


#2

Your pattern should be next:

  1. Subscribe and wait all the data

  2. Apply jQuery logic on all data is done from subscribtion

    Template.test.onCreated ->
    @sub = Meteor.subscribe(‘someData’)

    Template.test.onRendered ->
    @autorun =>
    if @sub.ready()
    Tracker.afterFlush =>
    @$(‘selector’).plugin()