问题描述
父模板
<template name="tracker">
<span id="destroyChild" class="btn" title="destroyTable"></span>
{{<child}}
</template>
'click span[id=destroyChild]'(e,template) {
//This works to remove the Parent template
//Blaze.remove(template.view);
Blaze.remove('what do I put here?');
},
我找不到要用作删除子模板的参数的任何东西。我不断收到Uncaught Error: Expected template rendered with Blaze.render
。
我给子模板一个ID,并尝试用selector
来调用它,但是没有运气。有任何想法吗?谢谢!
解决方法
您不应强制更改布局。 Blaze是一种反应式引擎,因此应以声明方式决定一切,例如:
<template name="tracker">
<span id="destroyChild" class="btn" title="destroyTable"></span>
{{#if show}}
{{> child}}
{{/if}}
</template>
Session.setDefault('show',true);
Template.tracker.helpers({
show() {
return Session.get('show');
}
});
...
'click span[id=destroyChild]'(e,template) {
Session.set('show',false);
},