【发布时间】:2020-09-29 16:33:32
【问题描述】:
我在我的 React Js Web 应用程序中使用这个组件:https://www.npmjs.com/package/react-faq-component。
const data = {
title: "FAQ (How it works)",
rows: [
{
title: "Lorem ipsum",
content: "Dolor sit amet",
},
],
};
我需要用我的 API 检索到的数据填充“行:”。
这是我的代码:
class Faqs extends Component {
constructor() {
super()
this.state = {
faqs: []
}
}
componentDidMount() {
let category = 'caategory1';
axios.get('https://myurl/api/faqs/'+category).then(response => {
this.setState({
faqs: response.data
})
})
}
render () {
const { faqs } = this.state;
const styles = {
titleTextColor: "black",
rowTitleColor: "black",
rowContentColor: 'grey',
}
const config = {
animate: true,
}
let data = {
title: 'FAQS (How it works)',
rows: [
// Here is where I'm trying to print the json data from the API
faqs.map(
(faq, index) => {
return (
`{title: ${faq.title}, content: ${faq.content}},`
)
}
)
]
}
}
我想这与转义有关,但我是 React 的初学者,所以如果有人能提供帮助,我将不胜感激。
谢谢!
【问题讨论】:
标签: javascript reactjs jsx