点击api后,我得到了包含空格和点的响应,通过这些响应,在如何将它们呈现在车把上时,情况非常令人困惑
{
Meta Data: {
1. Information: "Daily Time Series with Splits and Dividend Events",
2. Symbol: "MSFT",
3. Last Refreshed: "2020-02-25 11:20:58",
4. Output Size: "Full size",
5. Time Zone: "US/Eastern"
},
Time Series (Daily): {
2020-02-25: {
1. open: "174.2000",
2. high: "174.8400",
3. low: "169.8800",
4. close: "170.4300",
5. adjusted close: "170.4300",
6. volume: "16881624",
7. dividend amount: "0.0000",
8. split coefficient: "1.0000"
},
2020-02-24: {
1. open: "167.7700",
2. high: "174.5500",
3. low: "163.2300",
4. close: "170.8900",
5. adjusted close: "170.8900",
6. volume: "67892482",
7. dividend amount: "0.0000",
8. split coefficient: "1.0000"
}
}
这不起作用我已经尝试了很多东西,空格和点不允许在快速车把中渲染代码。请帮助
router.get('/stock/:name',(req,res)=>
{
let name = req.params.name;
console.log(name);
axios.get(`https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol=${name}&apikey=apikey).then((result)=>
{
var newData1 = result.data;
// console.log(newData1);
res.render('home/stock',{newData1});
})
})
如何在模板中呈现它因为响应中存在空格和点]
{{#each newData1}}
{{#each 'Time Series (Daily)'}}
<h5>{{this}}</h5>
{{/each}}
{{/each}}
newData1
转换为名为newData2
的新json。router.get('/stock/:name',(req,res)=>
{
let name = req.params.name;
console.log(name);
axios.get(`https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol=${name}&apikey=apikey).then((result)=>
{
const newData1 = result.data; // <-------- HERE, I will recommend 'const' instead of 'var' :)
const timeSeriesDaily = newData1['Time Series (Daily)'];
let newData2 = {}
let i = 0;
for (var prop in timeSeriesDaily) {
newData2[i] = {date: prop, data: timeSeriesDaily[prop]};
i++;
}
res.render('home/stock',{newData2});
})
})