我正在尝试在我的React组件中显示来自数组的数据。
我可以在浏览器开发者控制台中通过console.log()看到我需要的数据:
FinalRecords.js :: recordTitle: (4)
0: {members: Array(10), id: 62, title: 'RR 1980 Record 1', storeId: 1088}
1: {members: Array(10), id: 63, title: 'RR 1980 Record 2', storeId: 1088}
2: {members: Array(10), id: 64, title: 'RR 1980 Record 3', storeId: 1088}
3: {members: Array(10), id: 65, title: 'RR 1980 Record 4', storeId: 1088}
length: 4
[[Prototype]]: Array(0)
但是我似乎无法弄清楚如何获取title。
我尝试了很多不同的方法,其中这个是最近的一个:
render() {
const { recordId, records, bandName } = this.props;
var data = records.filter((r) => r.id === recordId);
var records = data.toArray();
console.log("FinalRecords.js :: recordTitle: ", records);
return <div> record - {findRecordTitle(records, recordId) } - {bandName || ''} </div>
}
}
function findRecordTitle(records, id) {
return records.find((record) => {
return record.id === id;
})
}
我需要通过使用id来获取记录的title。
但它总是空白的。
我做错了什么吗?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号