我正在尝试修改服务器端js。它采用 JSON 文件作为输入并呈现数据以生成 HTML 文件。

I am trying to modify server side js. which takes an json file as input and render the data to produce html file.

提问人:dpk45 提问时间:4/7/2017 更新时间:4/7/2017 访问量:68

问:

附加的代码将 json 作为输入,我正在尝试使用脚本呈现数据,以便它采用正确的格式。

我们需要修改“json to html.txt”服务器端 js,使 html 中的输出从输入 json 。

附图显示了右侧的输出。此输出必须采用格式。second image shows the required format

<!DOCTYPE html>
<html>
<body>



<p id="demo"></p>

<script>

var statement, i, j, x = "";
statement = {
"Financial statement:":
["NetIncomeLoss = ","- NetIncomeLossAttributableToNoncontrollingInterest","+ ProfitLoss = ","  + IncomeLossFromDiscontinuedOperationsNetO...","  + IncomeLossFromContinuingOperationsInclud... = ","    + apd_IncomeLossFromContinuingOperationsBeforeTaxes = ","      + OperatingIncomeLoss = ","        + SalesRevenueNet","        - CostOfGoodsAndServicesSold","        - SellingGeneralAndAdministrativeExpense","        - ResearchAndDevelopmentExpense","        - RestructuringCharges","        + apd_OtherIncomeExpenseNet","      + IncomeLossFromEquityMethodInvestments","      - InterestExpense","    - IncomeTaxExpenseBenefit","EarningsPerShareBasic = ","+ IncomeLossFromContinuingOperationsPerBasicShare","+ IncomeLossFromDiscontinuedOperationsNetOfTaxPerBasicShare","EarningsPerShareDiluted = ","+ IncomeLossFromContinuingOperationsPerDilutedShare","+ IncomeLossFromDiscontinuedOperationsNetO..."],
"2009-12-31":[251.8,5,256.8,0,256.8,340.3,345,2173.5,1568.6,244.1,27.2,0,11.4,26.9,31.6,83.5,1.19e-06,1.19e-06,0,1.16e-06,1.16e-06,0],"2008-12-31":[68.6,5,73.6,-21.4,95,102.1,114.1,2195.3,1629.7,247,33.2,174.2,2.9,24.5,36.5,7.1,3.3e-07,4.3e-07,-1e-07,3.2e-07,4.2e-07,-1e-07]
}

var spaceCount=[];
var financialStatement=[];


 var otherColumns = [];
  var output = '<table class="table" style="width:100%;"><tr>';
  Object.keys(statement).forEach(function (key, i) {
    output += '<th><pre>' + key + '</pre></th>';
    if (i > 0){
      otherColumns.push(key);
    }
  });
  output += '</tr>';

  statement[Object.keys(statement)[0]].forEach(function(val, i){
    var total = false;
    if (val.indexOf('=') > -1){
      total = true;
    }
   
    var printValue = '<td><pre>' + val + '</pre></td>';
    if (total){
      printValue = '<td><pre style="font-weight: bold;text-decoration: underline;">' + val + '</pre></td>';
    }
    otherColumns.forEach(function(key, j){
      if (total){
        printValue += '<td><pre style="font-weight: bold;text-decoration: underline;">' + statement[key][i] + '</pre></td>';
      }
      else
{
        printValue += '<td><pre>' + statement[key][i] + '</pre></td>';
      }
    });
    output += printValue + '</tr>';
  });
  output += '</table>';
 
document.getElementById("demo").innerHTML = output;

</script>

</body>
</html>

JavaScript HTML AngularJS、 JSON 服务器端

评论

0赞 Saurabh Verma 4/7/2017
您究竟在哪里面临问题?
0赞 dpk45 4/7/2017
如何用 total 排列特定行。

答: 暂无答案