0

我正在用 jqm 和 phonegap 开发一个应用程序。该应用程序由多个 html 页面组成,这些页面将根据从 Web 服务器返回的信息进行更新。

我最初的计划是在应用程序第一次加载时从 Web 服务器检索所有信息并预先填充其他 html 页面,这样用户在每个页面之间导航时就不必等待联系服务器。

function onDeviceReady() {

// pre-fetch pages so we can setup the main pages before the user gets to them
$.mobile.loadPage( "page2.html", { showLoadMsg: false } );
$.mobile.loadPage( "page3.html", { showLoadMsg: false } );


// Return JSON from php web server
    ....

// id of div on page2.html - update based on information returned from web server
$("#page2MainDiv").append('<p>hello!!!</p>');

}

我有两个问题:

1)上面的代码不起作用......我没有收到任何错误,但 html 没有更新 - 我看不出我哪里出错了,这让我发疯了!

2)这是一种明智的方法吗?由于我是移动和 Web 开发的新手,我不确定是否有更好的方法。

提前致谢

克里斯

4

1 回答 1

0

Try to make it easier. Instead of javascript, you may use simple "data-prefetch" attribute to links. Try to read this: JQuery Mobile Cahce & Prefetch. Loading pages may be a good idea, if you don't have a lot of data and subpages. Usually you don't know what subpage will user choose, or if he will choose any. In this case loading most, or even all data may be pointless. Again, if your app is small and does not require lot of data, you may use your approch. However I don't suggest it and don't use it in my apps. Loading data may be also expensive for the user, remember about this.

于 2012-09-15T20:58:38.710 回答