只是从Reactjs开始,我正在寻找最有效的代码来按照“渲染”部分中的表结构在下面显示数组。我一直在使用.map进行迭代,但没有成功。
在下面的代码示例中,我从节点的Url中获取数据,然后在localhost上进行表达。从我的React应用程序,我试图从本地主机获取数据,但是由于复杂的数组,我无法通过它获取数据 我该如何实现?
谢谢
Node-express server.js
const express = require('express');1
const bodyParser = require('body-parser');
const app = express();
const port = process.env.PORT || 5000;
var request = require("request")
var url = ""
request({
url: url,
json: true
}, function (error, response, body) {
app.get('/api/hello', (req, res) =>{
res.send({body});
})
})
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
app.post('/api/world', (req, res) => {
console.log(req.body);
res.send(
`data received: ${req.body.post}`,
);
});
app.listen(port, () => console.log(`Listening on port http://localhost:${port}/api/hello`));
preview of Json file
body:{
->info:{
tax "0"
discount "0"
minimum_spend "0"
delivery_charges "0"
last_updated "2 months 3 weeks ago"
}
->items:{
0:{name: 'sdasd',
id:1}
1:{name: 'sdasd',
id:1}
2:{name: 'sdasd',
id:1}
}
}
{{1}}
注意:“ body是info和item的父级,body和info都是“ object”类型,而item是数组类型