简体   繁体   English

jQuery UI Ajax选项卡-重新加载选项卡,还是更改选项卡位置?

[英]jquery ui ajax tab - reload tab, or change tab location?

I have a tab layout on one of my sites that shows a log of items. 我在一个站点上有一个选项卡布局,其中显示项目日志。 The items are "paged". 这些项目是“分页的”。

The tab is initially loaded as such ... 该选项卡最初是这样加载的...

<li><a href="/im/price_change_log/${item_id}">Price Log</a></li>

In the tab i have some icons that represent next and previous page. 在选项卡中,我有一些图标代表下一页和上一页。 On click I want to load the next page or previous page of results in this tab. 单击后,我想在此选项卡中加载结果的下一页或上一页。

How can I go about this? 我该怎么办? Do I need to change the url of the tab and then force a reload. 我是否需要更改选项卡的url,然后强制重新加载。 The url would be... 该网址将是...

/im/price_change_log/<item_id>/<page>

The js pager portion looks like ... js分页器部分看起来像...

function bind_ui(){
        $(".prev_page").click(function(){
            var page = current_page;
            console.log("Previous Page - current_page("+page+")");
        });
        $(".next_page").click(function(){
            var page = current_page;
            console.log("Next Page - current_page("+page+")");
        });
    };

So i guess my question is how do load the tab with the new url? 所以我想我的问题是如何用新的URL加载选项卡?

Above answer will not work in JQuery 1.9+ as describer here . 上面的答案将无法在JQuery 1.9+中用作此处的描述器。 To work with jquery ui tabs 1.9+ you have to do something like this 要使用jQuery ui tabs 1.9+,您必须执行以下操作

function bind_ui(){
    $(".prev_page").click(function(){
        var $tabs = $('#tabs').tabs();
        var selected = $tabs.tabs('option', 'active'); 
        if(selected != 0){
            $($tabs.data('uiTabs').tabs[selected - 1]).find('.ui-tabs-anchor').attr('href', newUrl);
            $tabs.tabs('active', selected - 1 );
            $tabs.tabs("load", selected - 1);
        }
    });
    $(".next_page").click(function(){
        var $tabs = $('#tabs').tabs();
        var selected = $tabs.tabs('option', 'active'); 
        if(selected < $tabs.data('uiTabs').tabs.length){
            $($tabs.data('uiTabs').tabs[selected + 1]).find('.ui-tabs-anchor').attr('href', newUrl);
            $tabs.tabs('active', selected + 1 );
            $tabs.tabs("load", selected + 1);
        }
    });
};

-EDIT 2- 编辑2

If you use Jquery 1.9, please see Zahid Riaz's answer 如果您使用Jquery 1.9,请参阅Zahid Riaz的回答

reloading tab (#tabs is the tab container): 重新加载标签(#tabs是标签容器):

function reloadCurrentTab(){
   var $tabs = $('#tabs').tabs();
   var selected = $tabs.tabs('option', 'selected'); 
   $("#tabs").tabs('load',selected);
}

changing tab: 更改标签:

$tabs.tabs('select',[INDEX OF THE TAB] );

obtains actual tab index: 获取实际的标签索引:

$tabs.tabs('option', 'selected'); // => 0

with your code.... it will be something like this: 与您的代码...。将是这样的:

function bind_ui(){
    $(".prev_page").click(function(){
        var $tabs = $('#tabs').tabs();
        var selected = $tabs.tabs('option', 'selected'); 
        if(selected != 0){
            $tabs.tabs("url" , selected-1, newUrl )
            $tabs.tabs('select',selected - 1 );
        }
    });
    $(".next_page").click(function(){
        var $tabs = $('#tabs').tabs();
        var selected = $tabs.tabs('option', 'selected'); 
        if(selected < $('#tabs').length){
            $tabs.tabs("url" , selected+1, newUrl )
            $tabs.tabs('select',selected + 1 );
        }
    });
};

-EDIT- -编辑-

I have found this code example in the jquery-ui homepage. 我在jquery-ui主页中找到了此代码示例。 You can put something like this: 您可以输入以下内容:

$("#tabs").tabs("url" , indexOfTheTab , newUrl );

... to change the URL to load. ...更改要加载的URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM