问题
I have a global template:
<template name="layout">
{{> header}}
{{> primaryNav}}
{{yield 'banner'}}
{{yield}}
{{> footer}}
{{> deleteConfirmModal }}
<span class="responsive-state"></span>
</template>
and when I do a route
@route 'blog',
path: '/blog/'
Everything works dandy. I can click back and forth through my header links and nav links with no glitching. But if I add a data context:
@route 'blog',
path: '/blog/'
data: ->
blogPosts: BlogPosts.find({}, {date: -1, time: -1})
When providing a data context, whenever I navigate to and away from a route in which a data context is provided all the templates nested in the layout template appear to re-render, causing glitches due to style classes that get wiped and then replaced. If I route to any other paths that do not require (and are not provided) a data context, the static templates do not re-render.
Is there a way to prevent certain static templates from re-rendering when providing a data context for a specific route?
回答1:
With Meteor in the current state- you should probably rely on renders breaking most stuff.
As for iron-router - the data
is stored in a ReactiveVar
, and it ensures that any changes to data
cause the layoutTemplate
to re-render (this might be an over-simplified interpretation).
You might be able to:
- Remove styles that animate on addition
- Try using preserve to keep the elements in-tact. (note: that it does not preserve anything but the element reference, all values/attributes get reset as per template generated element)
- Wait for meteor 1.0, or use one of the new template rendering previews which "patch" the DOM instead of re-inserting every element on render.
来源:https://stackoverflow.com/questions/20958299/meteor-js-iron-router-prevent-static-template-re-render-and-glitching