【发布时间】:2020-12-16 21:36:30
【问题描述】:
我有一个使用react 的前端。我想使用从 API 获取的数据中提取的参数在地图之后添加一个链接到调查页面。我有两个问题:
-
不知道怎么给链接加参数
-
函数映射后无法添加链接会报错。
这是我的代码:
export default function Dashboard() {
const [students, setstudents] = useState([]);
useEffect(() => {
const fetchStudents = async () => {
try {
const resp = await Axios({
method: "GET",
url: "http://localhost:3001//student/courses",
headers: {
"Content-Type": "application/json",
},
});
setstudents(resp.data);
} catch (err) {}
};
fetchStudents();
}, []);
const classes = useStyles();
return (
<GridContainer>
<GridItem xs={12} sm={6} md={3}>
<Card>
<CardHeader color="warning" stats icon>
<CardIcon color="warning">
<Icon>content_copy</Icon>
</CardIcon>
<p className={classes.cardCategory}>Completed surveys</p>
<h3 className={classes.cardTitle}>{students.toatl_voted}/{students.total_courses}</h3>
</CardHeader>
</Card>
</GridItem>
<GridItem xs={12} sm={12} md={12}>
<Card>
<CardHeader color="primary">
<h4 className={classes.cardTitleWhite}>Available Surveys</h4>
<p className={classes.cardCategoryWhite}>
Here is the remaining courses surveys to submit
</p>
</CardHeader>
<CardBody>
<Table
tableHeaderColor="primary"
tableHead={["Course Code", "Course Name", "Survey Link"]}
tableData={students && students.map((student) => [student.surveys.Course_code,
student.survey.Course_name])}
//href link should be added here as follow api: url/student/course/:sectionId/:departmentId it must be clickeable
/>
</CardBody>
</Card>
</GridItem>
</GridContainer>
);
}
【问题讨论】:
-
你用什么作为 ui 库?
-
所以你是说 fetch 返回 sectionId 和 departmentId?
标签: javascript node.js reactjs express web