gpt4 book ai didi

Meteor:使用 Blaze 更新集合后强制重新渲染整个模板

转载 作者:行者123 更新时间:2023-12-04 10:07:27 27 4
gpt4 key购买 nike

我有一个更改 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>

然后,我有一个 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>

这个模板的脚本会更改 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 ?
}
});

最佳答案

我认为这可能也是 meteor 方式的更好解决方案。

../clips.js

Template.clips.onRendered(function(){

this.autorun(function(){
Template.currentData();
});

});

template.autorun(runFunc)

You can use this.autorun from an onCreated or onRendered callback to reactively update the DOM or the template instance. You can use Template.currentData() inside of this callback to access reactive data context of the template instance.

http://docs.meteor.com/#/full/template_autorun

关于Meteor:使用 Blaze 更新集合后强制重新渲染整个模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23355878/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com