uni*_*nal 8 meteor meteor-blaze
我正在使用UI.render()和UI.insert()插入模板.
当我试图删除我插入的模板时,它似乎留在内存中并且不会调用被破坏的方法.
根据文档,如果我使用jquery删除元素,它应该清理属性.
我正在使用以下代码测试它:
的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>
Run Code Online (Sandbox Code Playgroud)
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);
};
}
Run Code Online (Sandbox Code Playgroud)
我做错了什么?
谢谢.
删除插入模板的一些选项:
a)在模板中使用close事件.
Template.foo.events({
'click a.close' : function(e, t) {
e.preventDefault();
t.__component__.dom.remove();
return false;
}
});
Run Code Online (Sandbox Code Playgroud)
b)使用帮助程序和实例引用
Template.foo.helpers({
destroy: function() {
this.dom.remove();
}
});
var instance = UI.renderWithData(Template.foo, { });
UI.insert(instance, $("#content")[0]);
instance.destroy();
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2944 次 |
最近记录: |