jQuery手风琴 - 没有崩溃

时间:2014-10-24 08:33:38

标签: javascript jquery accordion

实施分页时;在第2页标题不会崩溃。我该如何解决?我使用手风琴的属性可折叠并将其设置为true,但这不起作用。有任何想法吗? JSFiddle

var paginatorHandle = null;

jQuery.fn.extend({
paginateAccordion: function (options) {
    var currentPage = options.currentPage ?parseInt(options.currentPage, 10) : 0;
    var itemsPerPage = options.itemsPerPage ? parseInt(options.itemsPerPage, 10) : 5;
    var paginatorControl = options.paginatorControl;

    return new AccordionPaginator(this, currentPage, itemsPerPage, paginatorControl);
}
});
jQuery(document).ready(function () {
jQuery("#dalist").accordion({
    autoHeight: false
});

paginatorHandle = jQuery("#dalist").paginateAccordion({
    "currentPage": 0,
        "itemsPerPage": 3,
        "paginatorControl": jQuery("#accordionPaginator")
});

// initial paginate call
paginatorHandle.paginate();

jQuery("#accordionPaginator .nextPage").click(function () {
    paginatorHandle.nextPage();
});

jQuery("#accordionPaginator .previousPage").click(function () {
    paginatorHandle.previousPage();
});

jQuery("#accordionPaginator .goToPage").change(function () {
    var pageIndex = parseInt($(this).val(), 10);
    paginatorHandle.goToPage(pageIndex);
});
});


//this is the main class

function AccordionPaginator(element, currentPage, itemsPerPage, paginatorControl) {
this.element = element;
this.currentPage = currentPage;
this.itemsPerPage = itemsPerPage;
this.paginatorControl = paginatorControl;

// does the actual pagination (shows/hides items)
this.paginate = function () {
    var index = this.currentPage * this.itemsPerPage;

    element.accordion("option","activate", index);
    element.children().hide();

    if (index < 0) {
        this.element.children("div:first").show();
        this.element.children("h3:first").show();
    } else {

        this.element.children("div:eq(" + index + ")")
            .show();

        this.element.children("h3:eq(" + index + "),h3:gt(" + index + ")")
            .filter(":lt(" + this.itemsPerPage + ")")
            .show();
    }

    this.refreshControl();
};

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

抱歉迟到了 - 我离开了 通常,在这种情况下,简单的解决方案是这样的:

// make a function with the scipt/plugin/code that
// you need to execute repeatedly
function doSomething(param1, param2)
{
   // execute some code, usualy some plugin
   // like open modals, run ajax queries, make tables sortable
   // something that needs to be executed lots of times in a page
   // especially after another plugin is executed
}

   // then call your custom function inside your plugin's callback OR success
    $(selector).pluginFunction({
      option1: "data1",
      option2: "data2",
      on_callback_function({
        doSomething(param1, param2)
      })
    })

现在,我不知道你的插件是如何工作的,但如果插件支持回调/成功,你可能会应用上述逻辑。