zoukankan      html  css  js  c++  java
  • 接收Android数据 递归显示表格数据

    <html>

    <head>
    <title>展示</title>
    <script type="text/javascript" src="jquery-1.7.1.min.js"></script>
    <script type="text/javascript">
    var secondTdContent = {};
    var thisJson, thisID; //返回的json 点击的ID
    var thisType, thisTxtVal; //类型 文本框的值
    var thisNodeLevelId; //
    var androidjson;
    var secondTdContent = {};

    function testDiv() {
    // document.getElementById("show").innerHTML = document.getElementsByTagName("html")[0].innerHTML;
    }

    $(function() {
    //接收android传过来的json
    function connectWebViewJavascriptBridge(callback) {
    if(window.WebViewJavascriptBridge) {
    callback(WebViewJavascriptBridge)
    } else {
    document.addEventListener(
    'WebViewJavascriptBridgeReady',
    function() {
    callback(WebViewJavascriptBridge)
    },
    false
    );
    }
    }
    //发送json数据到android端
    connectWebViewJavascriptBridge(function(bridge) {
    bridge.init(function(message, responseCallback) {
    console.log('JS got a message', message);
    var data = {
    'Javascript Responds': '测试中文!'
    };
    console.log('JS responding with', a);
    responseCallback(data);
    });
    //接收到数据
    bridge.registerHandler("functionInJs", function(data, responseCallback) {
    // document.getElementById("show").innerHTML = ("data from Java: = " + data);
    //发送到android端的数据:responseData=jsons数据
    androidjson = data;
    initTable(androidjson);
    });
    });

    function initTable(androidjson) {
    androidjson = eval('(' + androidjson + ')');
    androidjson = JSON.parse(androidjson);
    thisJson = androidjson.data.maintainStandardPlateMissions;
    var template = androidjson.data;
    var plateList = template.maintainStandardPlateMissions;
    for(var plate_index = 0; plate_index < plateList.length; plate_index++) {
    var plate = plateList[plate_index];
    $("#model_content").append("<tr id='plate_" + plate.id + "'><td colspan='2' class='plateStyle'>" + plate.content + "</td> </tr>");
    var itemList = plate.maintainStandardItem1Missions;
    if(null != itemList && itemList.length > 0) {
    for(var item_index = 0; item_index < itemList.length; item_index++) {
    var item = itemList[item_index];
    $("#model_content").append("<tr id='item_" + item.id + "'><td>" + item.content + "</td><td id='item_next_" + item.id + "'></td></table>");
    var childList = item.maintainStandardItem2Missions;
    secondTdContent["content"] = "";
    if(null != childList && childList.length > 0) {
    for(var child_index = 0; child_index < childList.length; child_index++) {
    var child = childList[child_index];
    switch(Number(child.resultType)) {
    case 1: // 单选
    if(child.isSelected == "1") { // 只显示选中的值
    secondTdContent.content += child.name + "</br>";
    }
    break;
    case 2: // 多选
    if(child.isSelected == "1") {
    secondTdContent.content += child.name + "</br>";
    }
    break;
    case 3: // 输入
    if(child.textContent == null) {
    child.textContent = ""
    }
    secondTdContent.content += (child.name + ":" + child.textContent) + "</br>";
    break;
    case 4: // 单选 输入
    case 5: // 多选输入
    secondTdContent.content += child.isSelected == "1" ? (child.name + ":" + child.textContent + "</br>") : "";
    break;
    }
    // digui(child);
    }
    }
    $("#item_next_" + item.id).append(secondTdContent.content);
    }
    }
    }
    //有隐患的变色
    // $("#model_content input[data-troubleLevel]").parent().parent().css('background-color', 'red')

    }

    });

    //显示递归【暂时不用保留 扩展】
    function digui(child) {
    var childList = child.childList;
    if(null != childList && childList.length > 0) {
    secondTdContent.content += "(";
    for(var child_index = 0; child_index < childList.length; child_index++) {
    var child_child = childList[child_index];
    //secondTdContent["content"] +=child_child.nodeType+"|"+child_child.name;
    switch(child_child.nodeType) {
    case 0:
    if(child_child.isSelected == "1") {
    if(Number(child.troubleLevel) > 0) {
    secondTdContent.content += ('<input type="radio" disabled data-troubleLevel="' + child_child.troubleLevel + '" value="' + child_child.name + '" class="' + child_child.id + '" checked/>' + child_child.name);

    } else {
    secondTdContent.content += ('<input type="radio" disabled value="' + child_child.name + '" class="' + child_child.id + '" checked/>' + child_child.name);

    }

    } else {
    secondTdContent.content += ('<input type="radio" disabled data-troubleLevel="' + child.troubleLevel + '" value="' + child_child.name + '" class="' + child_child.id + '" />' + child_child.name);
    }
    break;
    case 1:
    if(child_child.isSelected == "1") {
    secondTdContent.content += ('<input type="checkbox" disabled value="' + child_child.name + '" class="' + child_child.id + '" checked/>' + child_child.name);
    } else {
    secondTdContent.content += ('<input type="checkbox" disabled value="' + child_child.name + '" class="' + child_child.id + '" />' + child_child.name);
    }
    break;
    case 2:
    if(!child_child.context) {
    secondTdContent.content += (child_child.name + '<input type="text" class="' + child_child.id + '" value="' + child_child.context + '" readonly/>');
    } else {
    secondTdContent.content += (child_child.name + '<input type="text" class="' + child_child.id + '" value="' + child_child.context + '" readonly/>');
    }
    break;
    case 3:
    if(child_child.isSelected == "1") {
    secondTdContent.content += ('<input type="radio" disabled value="' + child_child.name + '" class="' + child_child.id + '" checked />' +
    child.name + '<input type="text" class="' + child.id + '" value="' + child.context + '" readonly />');
    } else {
    secondTdContent.content += ('<input type="radio" disabled name="' + child_child.nodeLevel + '" value="' + child_child.name + '" class="' + child_child.id + '"/>' +
    child_child.name + '<input type="text" class="' + child_child.id + '" readonly />');
    }
    break;
    case 4:
    if(child.isSelected == "1") {
    secondTdContent.content += ('<input type="checbox" value="' + child_child.name + '" class="' + child_child.id + '" checked disabled/>' +
    child_child.name + '<input type="text" class="' + child_child.id + '" value="' + child_child.context + '" readonly/>');
    } else {
    secondTdContent.content += ('<input type="checbox" value="' + child_child.name + '" class="' + child_child.id + '" disabled/>' +
    child_child.name + '<input type="text" class="' + child_child.id + '" readonly/>');
    }
    break;
    }
    digui(child_child);
    }
    secondTdContent.content += ")";
    }
    }
    </script>
    <style type="text/css">
    * {
    margin: 0;
    padding: 0;
    }

    table tr td {
    border: 1px solid #b4b4b4
    }

    table {
    border-collapse: collapse;
    }

    .hidTrouble-color {
    background-color: red;
    color: #fff;
    }
    </style>
    </head>

    <body>
    <p>
    <xmp id="init" style="display:none">
    </xmp>
    </p>

    <table id="model_content" style="">

    </table>
    <!-- <input type="text" value="测试" id="test"/> -->
    <!-- <input type="button" value="显示" id="btn"/> -->
    </body>
    <!-- bootstrap -->

    </html>

  • 相关阅读:
    WPF 关于拖拽打开文件的注意事项
    asp.net core 3.1中对Mongodb BsonDocument的序列化和反序列化支持
    用百度webuploader分片上传大文件
    多线程学习笔记
    web.config数据库连接字符串加密
    Visual Studio 2010 常用快捷方式
    Team Foundation Server 2013 日常使用使用手册(四)分支与合并
    Team Foundation Server 2013 日常使用使用手册(三)上传新工程、创建任务、创建bug、设置预警
    Team Foundation Server 2013 日常使用使用手册(二)修改、签入、撤销、回滚、对比代码变更
    Team Foundation Server 2013 日常使用使用手册(一)-本地连接TFS、查看任务
  • 原文地址:https://www.cnblogs.com/lgjc/p/8550260.html
Copyright © 2011-2022 走看看