jCarousel:您可以删除所有项目并重新绑定到新集合吗? [英] jCarousel: Can you remove all items and rebind to a new collection?
本文介绍了jCarousel:您可以删除所有项目并重新绑定到新集合吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
jCarousel文档指出以下内容:
- 通过将回调函数itemLoadCallback作为配置选项,您可以动态地创建内容的项目.
{...}- jCarousel包含一种便捷方法add(),可以将要传递给 create 的项的索引和要创建的项的innerHTML字符串传递给该方法.
- By passing the callback function itemLoadCallback as configuration option, you are able to dynamically create (li) items for the content.
{...}- jCarousel contains a convenience method add() that can be passed the index of the item to create and the innerHTML string of the item to be created.
我的问题:
是否可以删除所有项目并重新绑定到新收藏夹?
Is it possible to remove all items and rebind to a new collection?
顺便说一句:我不一定需要一种便利方法"来做到这一点.我对变通办法非常开放.
仅供参考:
BTW: I don't necessarily need a "convenience method" to do this. I'm very open to workarounds.
FYI: This strategy doesn't seem to work.
推荐答案
您可以执行此操作,但是您需要保留对转盘的引用并在其上调用reset
.这可以通过使用传递给jcarousel函数的initCallback
选项来实现.
You can do this but you need to keep a reference to the carousel around and call reset
on it. This can be achieved by using the initCallback
option you pass to the jcarousel function.
function carousel_callback( carousel, state) {
// BWA-HA...I have the carousel now....FEEL THE POWER!
// reset empties it out
$('#reset-caro').click( function( evt ) {
carousel.reset();
});
// here's how to call add
$('#add-to').click( function( evt ) {
// ..this just adds to the first spot..modify as needed
carousel.add(0, "<li>O HAI!</li>");
});
}
$(document).ready(function() {
$('#mycarousel').jcarousel( {
initCallback: carousel_callback
});
});
这是我的HTML:
<a id="reset-caro" href="#">reset</a>
<a id="add-to" href="#">add</a>
<ul id="mycarousel" class="jcarousel-skin-tango">
<li>MOM</li>
<li>DAD</li>
<li>BROTHER</li>
<li>SISTER</li>
</ul>
这篇关于jCarousel:您可以删除所有项目并重新绑定到新集合吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文