【发布时间】:2018-03-26 09:36:32
【问题描述】:
我正在使用 Json Data 来填充我的 html 表,并且我已将这些 html 页面添加到 assets 文件夹中以供离线使用。在 Html 文件中,我包含了由 Json 数据填充的行和列的表。
我希望能够在 Internet 不可用时缓存 Json Data for Offline 视图,并在新的 Json 数据可用时覆盖现有数据。
有什么解决方案吗?
我的 index.html 包括
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="table-responsive">
<h1>Json</h1>
<br/>
<table class="table table-bordered table-striped" id="employee_table">
<tr>
<th>Class</th>
<th>Time</th>
</tr>
</table>
</div>
</div>
</body>
</html>
<script >
$(document).ready(function(){
$.getJSON("https://api.myjson.com/bins/8qktd", function(data){
var employee_data= '';
$.each(data, function(key, value){
employee_data += '<tr>';
employee_data += '<td>'+value.class+'</td>';
employee_data += '<td>'+value.time+'</td>';
employee_data += '</tr>';
});
$('#employee_table').append(employee_data);
});
});
</script>
我的 Json 文件包括
[
{
"id":"1",
"time":"10-15",
"class":"John Smith"
},
{
"id":"2",
"time":"10-15",
"class":"John Smith"
},
{
"id":"3",
"time":"10-15",
"class":"John Smith"
},
{
"id":"4",
"time":"10-15",
"class":"John Smith"
},
{
"id":"5",
"time":"10-15",
"class":"John Smith"
},
{
"id":"6",
"time":"10-15",
"class":"John Smith"
},
{
"id":"7",
"time":"10-15",
"class":"John Smith"
},
{
"id":"8",
"time":"10-15",
"class":"John Smith"
},
{
"id":"9",
"time":"10-15",
"class":"John Smith"
},
{
"id":"10",
"time":"10-15",
"class":"John Smith"
},
{
"id":"11",
"time":"10-15",
"class":"John Smith"
},
{
"id":"12",
"time":"10-15",
"class":"John Smith"
}
]
我的 Webview 包含代码,
mywebview.getSettings().setJavaScriptEnabled(true);
mywebview.setWebViewClient(new WebViewClient());
WebView mywebview = (WebView) findViewById(R.id.webView1);
mywebview.loadUrl("file:///android_asset/index.html");
【问题讨论】:
标签: javascript android html json android-studio