У меня есть только одна страница, ключ в том, чтобы в вашем документе был готов pagebeforechange или ondeviceready.
$(document).bind("pagebeforecreate",function( e, data ){
if ( typeof data.toPage === 'string' ){
var p = $.mobile.path.parseUrl( data.toPage );
if( u.hash.search( new RegExp( /^MyPageName/ ) ) !== -1 ) {
$.mobile.showPageLoading();
MyCodeToExecForThisPage( p, data.options );
e.preventDefault(); // tell jquery i will create a page not him
}
}
});
, так что теперь вам нужна функция для обработки страницы и отображенияhtml, вот что я делаю:
function SetPagesTemplate( ){
$page = $("#AllPage"); // this is the name of my page in the index file
$header = $page.children( "#AllHead" ); // my header so i can custom change
$content = $page.children( ":jqmData(role=content)" ); // the content area of page
$header.html( 'custom graphic or text' );
$content.html(''); // clear everything up
$footer = $page.children( "#allFoot" ); // hook into my footer bar
$footer.html( 'custom footer nav and links' );
}
ниже приведен код, отображаемый при переходе на страницу, для которой необходимо указать значение, например #person? personid = 22 моя страница - это персона, и я буду использовать идентификатор[personid] и, получая правильную информацию, я тогда заполню свою страницу ALLPAGES содержимым и заставлю jquery думать, что я на самом деле на # person.
// take note here that i take in urlObj [ this was p ] and options
function LoadPerson( urlObj, options ) {
try{
// lets get the number sent by stripping everything out
var id = urlObj.hash.replace( /.*personid=/,"" ),
extra = "";
SetPagesTemplate( ); // the code that sets the page so i dont have to repeat myself.
$.ajax({
url: "http:\/\/" + domain + "/Ajax/MobilePersonProfile",
type: "POST",
dataType: "json",
data: { id: id },
crossDomain: true,
success: function ( data ) {
//loop through data create rows
if( data.length === 0 ){ ThrowCustomAlert( 'Sorry, unable to load profile.', 'no profile available', true ); }
else {
// now deal with your data on this example your processed data would be called template
// all this page stuff was set up earlier so lets fill it
$content.append("<section><nav id='profilescroll'>" + extra + template + "</nav></section>" );
$page.page(); // make our page into a page
options.dataUrl = urlObj.href;
template = null;
data = null;
// above cleanup, on mobile device to keep memory leaks low
// now we navigate to our created page THIS
$.mobile.changePage( $page, options );
StartScroller( "profilescroll" );
HideLoading(); // lets hide the page loading
}
},
error: function ( jqXHR, textStatus, errorThrown ) { CustomError(errorThrown,'',"Profile",true); }
});
}
catch( ee ){ CustomError( ee.message, ee.description, "profile", true ); }
}
это все, что вам нужноэто все, что я когда-либо использовал, я не думаю, что видел примеры, подобные этому, мне пришлось в основном превратить все мое приложение в такой способ работы, чтобы уменьшить использование памяти на iphone 2 при использовании в качестве приложения телефонной пробелы, и это очень и оченьочень быстро с полной навигацией ajax.
Следует отметить, что вам нужна только навигация по хештегам, на вашей странице перед настройкой создайте новый if для каждой страницы, которую вы хотите.w
ну, надеюсь, это поможет
, как и требуется здесь, html для моей страницы:
<div data-role="page" id="AllPage" class="body" style="overflow:hidden;">
<header class="bar" id="AllHead"></header>
<div data-role="content" class="content" id="home"></div><!-- /content -->
<footer class="bar" id="allFoot"></footer>
</div><!-- /page -->