I have a template in which the DOM is changed, and I would like to rerender the template when saving to database. Before Blaze, Meteor would have rerendered the whole template if there was a reactive variable somewhere in the template, but now how can I do this ?
I have a collection of clips set up in an Iron router route :
ClipsController = RouteController.extend({
data: function() {
clips = Clips.find({}, {sort: {created: 1}});
return {clips: clips};
}
});
And a template for clips :
<template name="clips">
{{#each clips}}
{{> clip}}
{{/each}}
</template>
Then, I have a template for clip :
<template name="clip">
<article class="clip" id="{{_id}}">
{{{content}}}
<ul class="tags">
{{#each tags}}
<li><a href="/#{{this}}">#{{this}}</a></li>
{{/each}}
</ul>
</article>
</template>
And a script for this template which changes the DOM and then saves the clip :
Template.clip.events({
'click .edit': function(event, template) {
template.$('.tags li').each(function() {
$(this).text($(this).text().replace(/^#(.*)/, "$1"));
});
},
'click .save': function(event, template) {
var data = {
//...
};
Clips.update({_id: this._id}, data);
// How to rerender the template ?
}
});