这是小提琴(抱歉有警报)http://jsfiddle.net/PCcqJ/92/
var ractive = new Ractive({
template: '#templateOne',
partials: {
aPartial: '<div>Oh look, the partial is rendered!</div>'
}
});
function cb() {
alert('but now we unrender');
ractive.once('complete', function() {
alert('we rendered again, and now you can\'t see the partial content');
});
ractive.render('container');
}
ractive.render('container');
ractive.once('complete', function() {
alert('so we render the first time, and you can see the partial');
ractive.unrender().then(cb);
});
此处的部分不会重新渲染。为什么是这样?部分仍在部分对象中,并且它们尚未渲染,那么什么会阻止它们再次渲染?
这个小提琴会渲染、取消渲染,然后重新渲染,每次发生其中一种情况时都会向您发出警报。
我做了一个工作jsfiddle:https://jsfiddle.net/43gLqbku/1/
<div id='container'></div>
<script id="templateOne" type="x-template">
{{>aPartial}}
</script>
var ractive = new Ractive({
el:"#container",
template: '#templateOne',
partials: {
aPartial: '<div>Oh look, the partial is rendered!</div>'
}
});
function cb() {
alert('but now we unrender');
ractive.once('complete', function() {
alert('we rendered again, and now you can\'t see the partial content');
});
ractive.render('container');
}
//ractive.partials.part = '<div>this is a partial</div>';
ractive.once('complete', function() {
alert('so we render the first time, and you can see the partial');
ractive.unrender().then(cb);
});
在调用render之前需要调用ractive.once('completed')
你不需要 ractive.render("container");在活动代码下,因为它在第一次运行时自动呈现
在你的jsfiddle中你导入的ractive不起作用
你没有在 jsFiddle 活动代码中包含 el:"#container"