我知道一个是 react 源,而另一个不是。但我认为他们总是会给出相同的值(value)。
然后我在 Telescope 的源码中找到了以下代码:
var newTerms = Template.currentData().terms; // ⚡ reactive ⚡
if (!_.isEqual(newTerms, instance.data.terms)) {
instance.postsLimit.set(instance.data.terms.limit || Settings.get('postsPerPage', 10));
}
链接:https://github.com/TelescopeJS/Telescope/blob/master/packages/telescope-posts/lib/client/templates/posts_list/posts_list_controller.js#L33
因此,这两个值似乎有时会有所不同。什么时候?
最佳答案
根据 Meteor 的文档,关于 template.data
:
This property provides access to the data context at the top level of the template. It is updated each time the template is re-rendered. Access is read-only and non-reactive.
既然我们知道 the current data context is reactive ,因此可以在不重新渲染模板的情况下进行更改(这使得 react 性在 Blaze 上看起来非常流畅),此
if
编写语句是为了检查“真实”当前术语(存储在响应式(Reactive) Template.currentData()
中)与我们拥有的“先前”术语 相比是否发生了变化。当前模板上次呈现的时间 . (存储在非响应式(Reactive) template.data
中)总结一下,这个自动运行的作用是:
template.data
中的术语进行比较当模板呈现时 关于meteor - Template.currentData() 和 template.data 什么时候值不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32505601/