这是小提琴(抱歉警报)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);
});
Run Code Online (Sandbox Code Playgroud)
此处的部分不会重新渲染.为什么是这样?部分仍然在partials对象中,并且它们已被取消渲染,那么什么会阻止它们再次渲染?
这个小提琴渲染,渲染,然后重新渲染,每当其中一个发生时给你一个警报.
小智 0
我做了一个工作 jsfiddle:https ://jsfiddle.net/43gLqbku/1/
<div id='container'></div>
<script id="templateOne" type="x-template">
{{>aPartial}}
</script>
Run Code Online (Sandbox Code Playgroud)
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);
});
Run Code Online (Sandbox Code Playgroud)
您需要在调用 render 之前调用 ractive.once('completed')
你不需要 ractive.render("container"); 在活动代码下,因为它在第一次运行时自动呈现
在你的 jsfiddle 中你导入的 ractive 不起作用
您没有在 jsFiddle 活动代码中包含 el:"#container"
| 归档时间: |
|
| 查看次数: |
228 次 |
| 最近记录: |