ncubica
ncubica

Reputation: 8485

Template function is running twice on the loading the webpage

Hi guys do you know why the following function is calling twice when meteor start?

The first time items and posts variables result is 0 and then in the second run have the objects inside of them. I know this is maybe because the html render before the event, but that not answer why its running twice.

Template.postList.itemList = function()
{
    var items = Items.find().fetch();
    var posts = Posts.find().fetch();

    debugger;

    return Posts.find();
}

thanks

Upvotes: 1

Views: 110

Answers (1)

Tomasz Lenarcik
Tomasz Lenarcik

Reputation: 4880

I'm not sure if this is what you're asking about, but the itemList helper is first executed when the site is initially rendered. Note, that initially Items and Post collections contain no documents at all. As soon as some documents arrives from the server the template containing your helper will be rerendered, which causes the itemList function to be called for the second time.

Upvotes: 3

Related Questions