wyc
wyc

Reputation: 55323

How to update a Collection without reloading the template?

I created an event that saves a post each time the user inputs something (an tiny autosave system):

Template.postSubmit.events

  "keypress .simditor-body": function() {
    var post;
    post = {
        title: $("#input-title").val(),
        content: $("#input-content").val()
    };
    Posts.update(this._id, {
      $set: post
    });
    console.log("saved");
  }

enter image description here

(#input-content has the same content as .simditor-body) The problem is that the template reloads each time the user types in .simditor-body. How to solve this problem?

Upvotes: 2

Views: 80

Answers (1)

Shwaydogg
Shwaydogg

Reputation: 2509

Previous to Meteor 0.8 there was {{#constant}}, {{#isolate}}, and preserve, but these are now deprecated with blaze.

You can pass reactive as false in your query to tell meteor not to watch the collection for changes: http://docs.meteor.com/#find

For example:

YourCollection.find( yourMongoSelector, {reactive:false});

Upvotes: 1

Related Questions