问题描述
我的应用中有一个页面,其中包含用户正在处理的项目列表.
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/[new 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 - 暂时阻止模板重新渲染(禁用反应性)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!