如何将自己的参数传递给JQuery分页插件中的回调函数? [英] How can I pass my own parameter to the callback function in JQuery pagination plugin?

查看:76
本文介绍了如何将自己的参数传递给JQuery分页插件中的回调函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 jQuery分页插件文档中的回调定义.看来它只能获取自己的两个参数.因此,如何将额外的参数传递给回调函数.

According to the definition of callback in JQuery pagination plugin's documents. It seems that it only get tow parameters of its own.So, how can I pass extra parameter to the callback function.

回调

被称为回调函数 当用户点击分页时 关联.函数接收两个 参数:新页索引和 分页容器(DOM元素). 如果回调返回false,则 事件传播已停止.默认 值:function(){返回false;}.这 回调函数对于 分页功能!它 应该包含更新您的代码 内容.以获得快速的用户体验 您不应该通过AJAX加载内容 在此功能中.而是预加载 一些内容页面并在 具有此功能的人.

A callback function that is called when a user clicks on a pagination link. The function receives two parameters: the new page index and the pagination container (a DOM element). If the callback returns false, the event propagation is stopped. Default value: function(){return false;}. This callback function is essential for the functionality of the pagination! It should contain code that updates your content. For a fast user experience you should NOT load content via AJAX in this function. Instead, pre-load some content pages and switch between them with this function.

例如插件用法代码[摘自其演示]:

e.g code of plugin usage [ from its demo]:

附加分页插件:

$("#News-Pagination").pagination(122, {
    items_per_page:20,
    callback:pageselectCallback
});

回调函数:

    /**
     * Callback function that displays the content.
     *
     * Gets called every time the user clicks on a pagination link.
     *
     * @param {int}page_index New Page index
     * @param {jQuery} jq the container with the pagination links 
     *                 as a jQuery object
     */
     function pageselectCallback(page_index, jq){
       var new_content 
         = $('#hiddenresult div.result:eq(' + page_index + ')').clone();
       $('#Searchresult').empty().append(new_content);
       return false;
     }

非常感谢您!

推荐答案

使用JS中常见的自定义包装函数来实现这一目标.

Use a custom wrapper function, as is common in JS, to achieve that.

callback: function(jq1, jq2, ..., jqN) {
  return pageselectCallback(your1, your2, jq1, jq2, ..., jqN);
}

此处 jq1 jqN 是jQuery分页插件提供的参数,而 your1 your2 是参数您指定自己.

Here jq1 through jqN are the parameters given by jQuery pagination plugin, while your1, your2 are parameters you specify yourself.

重要提示::由于省略号,上述无效的JS语法...-进行更改以符合您的情况

IMPORTANT: The above is not valid JS syntax due to the ellipsis ..., - change to match your situation

这篇关于如何将自己的参数传递给JQuery分页插件中的回调函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆