Phonegap/Apache Cordova を使用してハイブリッド Android アプリを構築しています。アプリは Web API からデータを取得する必要があります。JSON を使用してデータを APP に提供しています。だから私は次のコードを得ました:
function init() {
document.addEventListener('deviceready', onDeviceReady, false);
var url = "http://23.21.128.153:3000/regions.json";var jsonresults;
$.getJSON(url,function(data){
jsonresults = data;
$.each(jsonresults, function(i,v){
$('#main-content').append('<li>'+jsonresults[i].name+'</li>');
});
});
}
また、html の本文には、main-content という div があります。Everythings は Eclipse ブラウザーでは正常に動作しますが、Android Emulator では動作しません。JSON を使用して Web API からデータを取得し、データを取得した後に動的に HMTL 要素を作成する別の方法があるかどうかはわかりません。