无法打印表格

时间:2016-06-28 07:45:52

标签: html node.js

我将在节点js中创建的表格发送到html网页,但是没有打印表格边界而是打印了一些随机字符和符号。

节点js代码是:

var express = require('express');
var app = express();
 var fs = require('fs')
var googlePlaySearch = require('google-play-search');
var prettyjson = require('prettyjson');
app.use(express.static('public'));
var csv = require('csv');
 var Table = require('cli-table');

app.get('/index.htm', function (req, res) {
 res.sendFile( __dirname + "/" + "index.htm" );
});


app.get('/process_get', function (req, res) {
first_name:req.query.first_name
 googlePlaySearch.fetch(req.query.first_name, function(err, response) {

var data =
'Category,name\n' +
 response.categories + ' ' +
response.name ; 

 var chars = {
  'top': '═', 'top-mid': '╤', 'top-left': '╔', 'top-right': '╗',
  'bottom': '═', 'bottom-mid': '╧', 'bottom-left': '╚',
  'bottom-right': '╝', 'left': '║', 'left-mid': '╟', 'mid': '─',
  'mid-mid': '┼', 'right': '║', 'right-mid': '╢', 'middle': '│'
 };

csv().from.string(data).to.array(function(data) {
   var
     headers = data[0],
     values = data.slice(1),
    aligns = [null,'right'],
    table = new Table({ head: headers, chars: chars, colAligns: aligns })
    ;

  table.push.apply(table, values);
   console.log(table.toString());
 });


 });

 });

 var server = app.listen(8080, function () {

 var host = server.address().address;
 var port = server.address().port;

 console.log("Example app listening at http://%s:%s", host, port)

})

和html代码是(index.htm)

<!DOCTYPE html>
<html>
 <head>
   <title>Package Details</title>
 </head>

<body>

  <h1><marquee style="color:yellow" >this is a page to find app details..     </marquee></h1>

  <center>

    <form id="f1" action="/process_get" method="GET">

        <h3 style="color:red">Package Name</h3>:<br>

             <input type="text" name="first_name">  <br><br>
              <input type="submit" value="Submit" style="font-size: 20px">
     </form>
 </center>

 </body>
</html>

请帮我解释一下代码

0 个答案:

没有答案