【问题标题】:Meteor: Changing a subtemplate without re-rendering parent templateMeteor:更改子模板而不重新渲染父模板
【发布时间】:2014-01-17 20:03:55
【问题描述】:

根据 Meteor 的文档,更改 #isolate 块内的内容不会导致父模板重新渲染,但我在以下示例中遇到不同的行为,当我更改时,'hello' 和 'a' 都会重新渲染'标题':

<head>
  <title>testing</title>
</head>

<body>
  {{> hello}}
</body>

<template name="hello">
{{#isolate}}
  {{> a}}
{{/isolate}}

{{#isolate}}
  {{> b}}
{{/isolate}}

</template>

<template name='a'>
 a: {{title}}
</template>

<template name='b'>
 b: {{desc}}
</template>

这里是javascript

if (Meteor.isClient) {
  Template.hello.rendered = function () {
    console.log('hello')
  };

  Template.a.rendered = function () {
    console.log('a')
  };

  Template.b.rendered = function () {
    console.log('b')
  };

  Handlebars.registerHelper('title', function() {
    return Session.get('title');
  });

  Handlebars.registerHelper('desc', function() {
    return Session.get('desc');
  });

}

我是不是误解了什么?我在这里看到了一个类似但未回答的问题: Meteor: Changing a subtemplate without changing parent template

【问题讨论】:

标签: meteor handlebars.js


【解决方案1】:

是的,父模板将被重新渲染,因为它必须被重新绘制。

虽然只有 {{#isolate}} 位内的部分会发生变化(包含模板 a),但模板 hello 会发生变化,这就是调用 re-rendered 的原因。

每当 Spark 渲染引擎(支持流星模板系统的当前版本)更改模板的 html 时,都会调用 .rendered()

在新的渲染引擎 Shark 中,.rendered() 在初始加载时只会被调用一次。这可能更符合您的要求,但仍处于预览版中

【讨论】:

猜你喜欢
  • 2013-09-02
  • 1970-01-01
  • 1970-01-01
  • 2020-07-07
  • 2014-12-12
  • 1970-01-01
  • 1970-01-01
  • 2017-11-16
  • 2014-09-22
相关资源
最近更新 更多