我有一个模板,其中DOM被更改,当保存到数据库时,我希望重新渲染模板。在Blaze之前,如果模板中有反应式变量,Meteor会重新渲染整个模板,但现在我该如何实现?
我在Iron路由器路线中设置了一个剪辑集合:
ClipsController = RouteController.extend({
data: function() {
clips = Clips.find({}, {sort: {created: 1}});
return {clips: clips};
}
});
还有一个关于剪辑的模板:
<template name="clips">
{{#each clips}}
{{> clip}}
{{/each}}
</template>
然后,我有一个剪辑的模板:
<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>
为这个模板编写一个脚本,它可以更改DOM并保存剪辑 :
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 ?
}
});