1

I am using $.mobile in my app. I must create my own routing system. I bind observer on hashchange and I pull out interesting data from location.hash. I have a problem - jQuery.mobile removes the hash sign from location.hash if it has a slashes ( e.g. from 'lalal/#controller/action/param' to 'lalal/controller/action/param' and $.mobile says in yellow box Error Loading Page.

I tried to unbind existing "hashchange" in first, but then pages not load automatically ( what I require ).

How to prevent changes of hash, but that jQuery must still load the page automatically( e.g. by its ID declared in element having data-role='page')? . Below is a fragment of my router class: ( Router.load doesn't change location.hash )

__construct: function() {   

        var that = this; 
        $( window ).bind( "hashchange" , function( e ) {
            //e.stopImmediatePropagation()
            that.load( this.location.hash  ); 

        });  
    }
4

2 に答える 2

6

ベータ3で追加されたjQueryMobileの「pushState」プラグインと戦っていると思います(私は信じています)。このプラグインは、次のコードで無効にできます(jQuery Mobile JavaScriptファイルを含める前に使用)。

$(document).on('mobileinit', function () {
    $.mobile.pushStateEnabled = false;
});

ここでドキュメントをチェックアウトしてください(「pushStateプラグイン」セクションに注意してください):http://jquerymobile.com/demos/1.0rc3/docs/pages/page-navmodel.html

于 2011-11-16T23:03:41.370 に答える
0

jqueryを含めた後、jquery.mobile-1.xyjsを含める前に、htmlに次を追加します。

<script>
$(document).bind("mobileinit", function(){
        $.mobile.pushStateEnabled = false;
        $.mobile.ajaxEnabled = false;
        $.mobile.hashListeningEnabled = false;
});
</script>
于 2012-10-06T21:16:35.730 に答える