Android:HTML:动态附加表不起作用

时间:2013-11-07 12:54:18

标签: javascript android html json webview

我正在编写一个Android代码,我必须从数据库中解析数据,并在HTML视图中显示相同的内容,该列表显示在webview中。

以下是我使用的HTML:

    <!doctype html>
    <html>
        <head>
            <meta charset="utf-8">
            <meta name="viewport" content="width=device-width,initial-scale=1">
            <title>Lead Manager</title>
            <link rel="stylesheet" href="themes/Bootstrap.css">
            <link rel="stylesheet" href="themes/jquery.mobile.structure-1.2.0.min.css" />
            <script src="themes/jquery-1.8.2.min.js"></script>
            <script src="themes/jquery.mobile-1.2.0.min.js"></script>
            </head>
        <body>
           <div data-role="page" data-theme="a">
            <div data-role="header" data-position="inline">
                <h1>Lead Manager</h1>
            </div>
            <div data-role="content" data-theme="a">
                <h2>List of Leads</h2>          
            </div>
           </div>
           </body>  

     <!-- Javascript -->
        <script src="assets/js/jquery-1.8.2.min.js"></script>
        <script src="assets/bootstrap/js/bootstrap.min.js"></script>
        <script src="assets/js/jquery.backstretch.min.js"></script>
        <script src="assets/js/jquery.countdown.js"></script>
        <script src="assets/js/scripts.js"></script>
     <script>
        $(document).ready(function(e) { 
            var data = Android.getLeads();
            data = [{"date":"20101231","Rating":"5","NumberofDays":"10"}];  
            var items = [];
            var date;
            var name;
            var status;
            eval("var x = " + data + ";");
            var y = JSON.stringify(x);                      
            $.each(x, function(key,val){
                items.push('<tr><td>' + val.date + '</tr></td>');   
            });                         
            $('<table/>', {     
                html: items.join('')
                }).appendTo('body');            
          });         
       </script>
</html>

Android.getLeads()给出的JSON结果类似于我在下一行中提到的结果。

我只是试图查看ITEMS []中的列表,并且按预期填充。但是,appendTo('body')无效。你能帮忙吗? Webview设置如下:

    WebView webView = new WebView(this);
    setContentView(webView);
     //Enable Java scripts
     webView.getSettings().setJavaScriptEnabled(true);
     webView.getSettings().setLoadWithOverviewMode(true);
     webView.getSettings().setUseWideViewPort(true);
     webView.getSettings().setAllowFileAccess(true);
     webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
     webView.setScrollbarFadingEnabled(false);
     webView.addJavascriptInterface(new WebAppInterface(this), "Android");
    String url = "file:///android_asset/screen/list.html";
    webView.loadUrl(url);
    //setContentView(R.layout.activity_main);

    webView.setWebViewClient(new WebViewClient(){
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url){
            return false;
        }
    });

有人可以帮助为什么没有添加表格吗?

0 个答案:

没有答案