jquery – jCarousel:你能删除所有项目并重新绑定到新的集合吗?

jCarousel documentation声明如下:
  • 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?

顺便说一句:我不一定需要一种“便利方法”来做到这一点.我对解决方法非常开放.
仅供参考:This strategy似乎不起作用.

解决方法

你可以这样做,但你需要保持对旋转木马的引用并在其上调用重置.这可以通过使用传递给jcarousel函数的initCallback选项来实现.
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>

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...