【发布时间】:2021-01-24 19:18:54
【问题描述】:
我有一个调用子模板的父模板。我想通过按一下按钮来杀死子模板。
父模板
<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 调用它,但没有运气。有任何想法吗?谢谢!
【问题讨论】:
-
不渲染到DOM的时候,child不是自动销毁了吗?
-
我想是这样,但你的目的是什么?
-
我假设在你的代码中
{{<child}}实际上是{{> child}},对吧? -
在使用 Meteor 的五年里,我从来没有打电话给
Blaze.remove,就像 Jan 建议的那样,你可能也不需要。您可能应该找到一种被动的方式来执行此操作,即,使用您在单击按钮时更改的条件来保护子项的包含。
标签: javascript node.js templates meteor meteor-blaze