I am looking for a simple example showing how to use JQueryMobile to render a page that has been dynamically assembled on the client side. $.mobile.autoInitialize used to work a few versions ago, and now we have $.mobile.autoInitializePage but I can't seem to figure out how to do it or find any examples of people that are using it.
My best effort (THIS NOW WORKS - was calling setting autoInitializePage too early before):
<html>
<head>
<link class="jsbin" href="http://code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.min.css" rel="stylesheet" type="text/css" />
<script class="jsbin" src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
<script class="jsbin" src="http://code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.min.js"></script>
<script>
$.mobile.autoInitializePage = false
</script>
</head>
<body>
</body>
<!-- coffeescript makes multiline strings easy -->
<script src="http://jashkenas.github.com/coffee-script/extras/coffee-script.js"></script>
<script type='text/coffeescript'>
$('body').html "
<div data-role='page'>
<div data-role='header'><h1>Title</h1></div>
<div data-role='content'><p>Page content goes here.</p></div>
<div data-role='footer'><h4>Page Footer</h4></div>
</div>
";
$.mobile.initializePage();
</script>
</html>
开发者_如何学编程
Result here: http://jsbin.com/apocol/2 Mess around with it here: http://jsbin.com/apocol/2/edit#html
I am not sure of the performance impact or other possible gotchas but I have used this successfully with dynamically updated pages when I want to force a complete refresh.
$("#MyPage").page("destroy").page();
精彩评论