$ e.mobile.history中的activeIndex行为不像预期的那样

时间:2013-07-12 10:03:25

标签: jquery jquery-mobile

我制作了一个jquery移动应用程序,可在两页之间切换。在pagebeforeshow事件中,我使用来自JSON对象的数据填充一些dom元素。当用户点击后退按钮时,我从历史堆栈中获取特定页面的数据的ID(我把它放在第一个onPageBeforeShow事件中)。

onPageBeforeShow: function() {

        // if fact id already exists in history stack take it from there (only happens when "back" is pressed)
        var urlh = $.mobile.urlHistory;
        if( "factId" in urlh.stack[urlh.activeIndex] ) {

            // load 
            cp10.score.currentFactId = urlh.stack[urlh.activeIndex].factId;

        } else {

            // store fact id in history object
            urlh.stack[urlh.activeIndex].factId = cp10.score.currentFactId;
        } 

        ... go on and fill dom elements with current id

适用于后退按钮。当我再次向前推进时,$ e.mobile.history.activeIndex元素有一个有趣的行为。例如,我在应用程序中向前移动了三页,因此activeIndex为3.然后使用浏览器后退按钮我去...

... back:activeIndex是2 back:activeIndex为1 back:activeIndex为0 forward:activeIndex为1 forward:activeIndex为0

我认为应该是2。我很困惑。

浏览器前进按钮按下会导致activeIndex减少的原因是什么?

0 个答案:

没有答案