首先,非常感谢https://stackoverflow.com/对我一生的编码贡献,这是我对https://stackoverflow.com/的第一个疑问
这是我的问题
这是我的前端json.js文件,可以正常工作:
const Subjects=[
{id:1, selectGrade: "LKG", GradeName: "LKG",
Detail: [
{ Subject: "English", Content: "Private"},
{ Subject: "Math", Content: "Private"}
]},
{id:2, selectGrade: "UKG", GradeName: "UKG",
Detail: [
{ Subject: "English", Content: "Private"},
{ Subject: "Math", Content: "Private"},
{ Subject: "Punjabi", Content: "Private"}
]},
{id:3, selectGrade: "class-1", GradeName: "1st",
Detail: [
{ Subject: "English", Content: "PSEB"},
{ Subject: "Math", Content: "PSEB"},
{ Subject: "Punjabi", Content: "Private"},
{ Subject: "Hindi", Content: "Private"},
{ Subject: "EVS", Content: "Private"},
{ Subject: "Computer Science", Content: "Private"},
{ Subject: "General Knowledge", Content: "Private"},
{ Subject: "Drawing", Content: "Private"}
]}
];
export default Subjects;
这是我在后端{在 subject_details 表 subject_id 是外键}中的api的代码
const express = require('express');
const Router = express.Router();
Router.get("/", (req, res)=>{
db.query("SELECT GradeName, Subject, Content FROM subjects INNER JOIN subject_details ON subjects.subject_id = subject_details.subject_id", (err, rows, fields) =>{
if(!err)
{res.send(rows);}
else
{console.log(err);}
})
})
module.exports = Router;
它会给我这样平坦的结果:
[{"GradeName":"LKG","Subject":"English","Content":"Private"},{"GradeName":"LKG","Subject":"Math","Content":"Private"},{"GradeName":"UKG","Subject":"English","Content":"Private"},{"GradeName":"UKG","Subject":"Math","Content":"Private"},{"GradeName":"UKG","Subject":"Punjabi","Content":"Private"}]
我想要结果作为我的json文件。我尝试了太多,但在互联网上没有任何有用的发现。
请帮助我
预先感谢