【发布时间】:2013-10-27 15:27:52
【问题描述】:
我做了一些实验,发现 Meteor 会刷新 <template> </template> 块中的所有内容,只要其中一个值发生变化,例如:{{test}},其中...
<body>
...
<div id="main-pane">
{{> todos}}
</div>
...
</body>
<template name="todos">
{{test}}
{{#if any_list_selected}}
<div id="items-view">
...
<ul id="item-list">
{{#each todos}}
->{{testa}}
{{> todo_item}}
{{/each}}
</ul>
...
</div>
{{/if}}
</template>
在 .js 文件中设置一个 setTimeout 来查找 {{test}} 和 {{testa}} 的预期变化:
Session.setDefault('test', 'aaa');
Template.todos.test = function () {
return new Date().getTime() + Session.get('test');
};
setTimeout(function () { Session.set('test', 'bbb'); }, 2000);
Template.todos.testa = function () {
return new Date().getTime(); //the timestamps will be refresh at the same time that test will do...
};
无论{{testa}} 放在模板中的什么位置,它显示的时间戳都会在我们每次执行Session.get('test') 时更新。
我不知道这是否是一个有效的实验......所以我想知道这是否有效:所有模板都重新渲染?因为我认为反应式模板是别的东西......更漂亮......(?)
【问题讨论】:
标签: meteor