删除流星0.8.0中插入的模板 [英] Remove inserted template in meteor 0.8.0

查看:68
本文介绍了删除流星0.8.0中插入的模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用UI.render()和UI.insert()插入模板.

I am inserting templates using UI.render() and UI.insert().

当我尝试删除插入的模板时,它似乎保留在内存中,并且未调用被销毁的方法.

When I tried to remove the template I inserted, it seems to stay in memory and the destroyed method is not called.

根据文档,如果我使用jquery删除元素,它应该清理属性.

According to the documentation, it should clean up property if I use jquery to remove the element.

我正在使用以下代码对其进行测试:

I'm testing it using the following code:

test.html:

test.html:

<head>
  <title>removeTest</title>
    <style>
        #content {
            height: 500px;
            width: 500px;
            background-color: gray;
        }
    </style>
</head>    

<body><div id="content"></div></body>    

<template name="foo"><div id="{{id}}">Foo</div></template>

test.js:

if (Meteor.isClient) {
    UI.body.events({
        "click": function(event) {
            var instance = UI.renderWithData(Template.foo, { });
            UI.insert(instance, $("#content")[0]);
        }
    });    

    Template.foo.created = function() {
        this.data.id = "handle";
        var self = this;
        this.x = setInterval(function() { console.log("running...") }, 1000);
        setTimeout(function() { $("#handle").remove() }, 1000);
    };    

    Template.foo.destroyed = function() {
        // never called.
        clearTimeout(this.x);
    };
}

我做错了什么?

谢谢.

推荐答案

某些选项可删除插入的模板:

Some options to remove inserted templates:

a)在模板中使用关闭事件.

Template.foo.events({
  'click a.close' : function(e, t) {
    e.preventDefault();

    t.__component__.dom.remove();
    return false;
  }
});

b)使用帮助程序和实例引用

Template.foo.helpers({
  destroy: function() {
    this.dom.remove();
  }
});

var instance = UI.renderWithData(Template.foo, { });
UI.insert(instance, $("#content")[0]);
instance.destroy();

这篇关于删除流星0.8.0中插入的模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆