Meteor.js-暂时阻止模板重新渲染(禁用反应性) [英] Meteor.js - temporarily prevent a template from re-rendering (disable reactivity)
问题描述
我的应用程序中有一个页面,其中包含用户正在处理的项目的列表.
I have a page in my app with a list of Projects the user is working on.
当他们想添加一个新项目时,我会显示一个模态表格以获取该项目的名称.
When they want to add a new project, I show a modal form to get the name of the project.
如果他们单击确定",我将创建项目并使用Meteor.Router重定向到/project/[新项目ID].
If they click 'OK' I create the project and redirect to /project/[new project id] using Meteor.Router.
但是,在重定向之前,我会自动在用户的项目列表中看到新的项目名称.
However, just before the redirect, I see the new project name automatically to the user's list of projects.
我想避免这种不必要的重新渲染,因为这会导致短暂更新内容.
I want to avoid this unnecessary re-rendering, which causes a brief flash of updated content.
有没有一种方法可以防止重新呈现我的项目列表的模板?
Is there a way to prevent the template for my list of projects from re-rendering?
推荐答案
您可以将包含此内容的html放入{{#constant}}
块中. 基于常量的文档
You can put your html containing this into a {{#constant}}
block. Docs on constant
例如
{{#constant}}
{{#each ...}}
....
{{/each}}
{{/constant}}
另一种选择是禁用模板助手中的反应性,例如,如果有
Another option is to disable reactivity in your template helper e.g if you have
Template.home.mydata = function() { return MyCollection.find() }
将其更改为使用reactive:false
作为选项
change this to use reactive:false
as an option
Template.home.mydata = function() { return MyCollection.find({}, {reactive:false}) }
这样可以显示初始更改,但不使用任何更新,因此不会进行重新渲染.
This way the initial changes are shown but any updates aren't used so there wouldn't be a re-render.
这篇关于Meteor.js-暂时阻止模板重新渲染(禁用反应性)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!