我正在为一些滑块使用装饰器,如下所示:
content = new Ractive({
el: '.wrapper',
template: templates.wrapper,
partials: templates,
data : { ... },
decorators: {
carousel: function( node )
{
console.log( 'carousel init' );
carousel = $( node ).owlCarousel({
items: 1,
navigation: false
});
return {
teardown: function () {
console.log( 'carousel destroy' );
carousel.trigger('destroy.owl.carousel').removeClass('owl-carousel owl-loaded');
carousel.find('.owl-stage-outer').children().unwrap();
}
}
}
}
}正如您在日志中看到的那样,当在具有inited的模板之间交换旋转木马时,会在新模板的装饰器为initiated之后触发第一个装饰器teardown,因此第二个模板上的旋转木马获得torn down,而不是第一个模板中的torn down。

我做错什么了吗?谢谢!
更新
我在这里做了个花招:https://jsfiddle.net/05sq8o2k/6/
如果您收到警告,一定要点击load unsafe scripts,因为据我所见,ractivejs cdn不支持https,所以jsfiddle现在有点不同意它。
发布于 2016-01-20 15:09:47
https://stackoverflow.com/questions/34885567
复制相似问题