我试图使用cli-table显示我在控制台上从api收到的数据。 api电话,一切正常。我只是在显示输出时遇到问题。这是我的代码
const
url = require('./url'),
Table = require('cli-table2'),
fs = require('fs'),
inquirer = require('inquirer')
let table = new Table({
head: ['Name', 'Type', 'Language',
'Genres', 'Status', 'Premiered', 'OfficialSite', 'Schedule', 'Rating', 'Streamed On', 'Externals', 'Images', 'summary'
],
colWidths: [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
});
const search = (item) => {
let shows = []
url.wordsearch(item)
.then(result => {
//console.log(result)
result.forEach(element => {
shows.push({ 'name': element.show['name'], 'value': element.show['id'] })
})
//console.log(shows)
inquirer.prompt([{
type: 'checkbox',
message: 'select tvshows you want see',
name: 'tvshow',
pageSize: 25,
choices: shows,
validate: (answer) => {
if (answer.length < 1) {
return "You must choose at least one card";
}
return true;
}
}]).then((answer) => {
//console.log(answer)
printresult(answer)
})
})
.catch(err => console.log(err))
}
const printresult = (answer) => {
answer.tvshow.forEach(show => {
url.idsearch(show)
.then(element => {
clean(element)
table.push([element['name'],
element['type'],
element['language'],
element['genres'],
element['status'],
element['premiered'],
element['officialSite'],
`Time :${element['schedule']['time']} \n Days: ${element['schedule']['days']}`,
element['rating'],
` name:${element['network']['name']}\n Country: ${element['network']['country']}`,
`tvrage:${element['externals']['tvrage']}\n thetvdb:${element['externals']['thetvdb']}\n imdb:${element['externals']['imdb']}`,
`medium:${element['image']['medium']}\n original:${element['image']['original']}`,
element['summary']
])
console.log(table.toString())
})
})
}
我做错了什么?我想要输出正确的表格格式,没有...或任何东西。 printresult方法执行打印到控制台的工作。我附上了输出的屏幕截图。