我正在尝试在Express.js中创建REST API,但是我遇到了一些问题,希望有人能帮助我)
我的Express.js代码:
router.get('/apps/download/:downloadId', function (req, res, next) {
const opts = Object.assign({downloadId: req.params.downloadId}, req.query);
gplay.download(opts)
.then(res.json)
.catch(next);
});
我的Node.js应用jQuery代码是:
const data = $( '.row' ).eq( 6 ).find( 'table tr' ).map( function() {
const a = $( this ).find( 'td:first-child a' );
const td = $( this ).find( 'td:last-child' );
return {
version: a.text(),
href: a.attr( 'href' ),
date: td.text()
}
}).get();
console.log( data )
const sdata = $( '.row' ).eq( 7 ).find( 'table tr' ).map( function() {
const a = $( this ).find( 'td:first-child a' );
const td = $( this ).find( 'td:last-child' );
return {
version: a.text(),
href: a.attr( 'href' ),
date: td.text()
}
}).get();
console.log( sdata )
因此,当我在浏览器中打开'/apps/download/:downloadId'
时,它仅显示console.log:
[
]
[
{
version: '1.0.2',
href: '/download-app/com.playgendary.kickthebuddy/5_com.playgendary.kickthebuddy_2018-06-09.apk/',
date: 'June 9, 2018'
},
{
version: '1.0.1',
href: '/download-app/com.playgendary.kickthebuddy/4_com.playgendary.kickthebuddy_2018-05-28.apk/',
date: 'May 28, 2018'
},
{
version: 'Varies with device',
href: '/download-app/com.playgendary.kickthebuddy/5_com.playgendary.kickthebuddy_2018-05-22.apk/',
date: 'May 22, 2018'
}
]
但是,在选项卡浏览器中,我只会得到一个清晰的窗口:
Console.log结果:
所以我需要在JSON页面上的REST API中获取所有这些数据,所以我该怎么办?