我做了一些实验,我发现Meteor会刷新<template> </template>
块中的所有内容,只要一个值发生变化,例如:{{test}},就在其中...... < / p>
<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')
时,它显示的时间戳都会更新。
我不知道这是否是一个有效的实验...所以我想知道这是否正确:所有模板都重新渲染?因为我认为反应模板是别的...更美丽......(?)
答案 0 :(得分:1)
如果要在同一模板中保留值,则必须使用单独的模板或隔离。
示例:
<template name="todos">
{{#each todos}}
{{>todo_item}}
{{/each}}
</template>
<template name="todo_item">
{{name}}{{task}}
</template>
或者使用隔离物:
<template name="todos">
{{#each todos}}
{{#isolate}}
{{name}}{{task}}
{{/isolate}}
{{/each}}
</template>
答案 1 :(得分:1)
我刚刚发现了这个:Ractive.js !!
“这种外科手术 DOM操作比不断删除视图更有效,只是为了重新渲染它们,它比手动更新元素更加优雅。(!)在这个例子中,Ractive .js构造一个并行的DOM表示,它意识到它对user和messages.unread的依赖性。 当这些值发生变化时,它确切地知道真正DOM的哪些部分需要更新。“
http://www.ractivejs.org/ http://www.theguardian.com/info/developer-blog/2013/jul/24/ractive-js-next-generation-dom-manipulation
太神奇了!去做例子:http://www.ractivejs.org/examples/和互动学习:http://learn.ractivejs.org/#!/hello-world/1
答案 2 :(得分:0)
您应该查看该网站:eventminded.com 有一两个截屏视频将为您提供了解流星如何工作的一切。 这比我认为的文字答案更好