if each single template has content update it will rerender the whole page ?
不,但它所有的父母的渲染事件都会被触发!实际上,渲染事件像 dom 事件一样传播。并且当特定模板中的响应式数据发生更改时,其内容及其所有子模板将被重新渲染!但不是他的父母!那么“恒定”和“孤立”是做什么的呢?我认为弄清楚它们的最好方法是做一些测试。这是一个简单的测试:html:
<head>
<title>meteor_test</title>
</head>
<body>
{{> main}}
</body>
<template name="main">
This is main template!
{{> subA}}
{{> subB}}
</template>
<template name="subA">
<div>
----This is subA! Input is surrounded by "constant"!
{{#constant}} <input /> {{/constant}}
Reactive data: {{reactiveData}}
{{> subA_A}}
</div>
</template>
<template name="subA_A">
<div>
--------This is subA_A!
<input type="text" />
Reactive data: {{reactiveData}}
</div>
</template>
<template name="subB">
<div>
----This is subB! Reactive data is surrounded by "isolate"!
<input type="text" />
Reactive data: {{#isolate}} {{reactiveData}} {{/isolate}}
{{> subB_A}}
</div>
</template>
<template name="subB_A">
<div>
--------This is subB_A!
<input type="text" />
Reactive data: {{reactiveData}}
{{> subB_A_A}}
</div>
</template>
<template name="subB_A_A">
<div>
------------This is subB_A_A!
<input type="text" />
Reactive data: {{reactiveData}}
</div>
</template>
js:
if (Meteor.isClient) {
Template.main.rendered = function () {
console.log('main is rendered at %s', new Date());
};
Template.subA.helpers({
reactiveData: function () {
return Session.get('subA');
}
});
Template.subA.rendered = function () {
console.log('subA is rendered at %s', new Date());
};
Template.subB.helpers({
reactiveData: function () {
return Session.get('subB');
}
});
Template.subB.rendered = function () {
console.log('subB is rendered at %s', new Date());
};
Template.subA_A.helpers({
reactiveData: function () {
return Session.get('subA_A');
}
});
Template.subA_A.rendered = function () {
console.log('subA_A is rendered at %s', new Date());
};
Template.subB_A.helpers({
reactiveData: function () {
return Session.get('subB_A');
}
});
Template.subB_A.rendered = function () {
console.log('subB_A is rendered at %s', new Date());
};
Template.subB_A_A.helpers({
reactiveData: function () {
return Session.get('subB_A_A');
}
});
Template.subB_A_A.rendered = function () {
console.log('subB_A_A is rendered at %s', new Date());
};
}
使用 chrome's/firebug 的控制台更改会话数据,看看会发生什么。注意这些输入中输入的文本在reactive改变时是否会被清除(意味着被重新渲染)以及是否触发了渲染事件。
……对不起我的英语也^_^