我有这个组件,它接收作为该类实例的projectListId
作为道具:
export class ProjectListModel {
constructor() {
this.data = [{
"projectId": 1,
"clientId": 1,
"projectDescription": "description1",
"projectMailingList": "mailingList1",
"projectImageUrl": "imageUrl1",
"projectCreationDate": "apr 29, 2019",
"projectVersion": 1
},
{
"projectId": 2,
"clientId": 1,
"projectDescription": "description2",
"projectMailingList": "mailingList2",
"projectImageUrl": "imageUrl2",
"projectCreationDate": "apr 29, 2019",
"projectVersion": 1
},
{
"projectId": 3,
"clientId": 1,
"projectDescription": "description3",
"projectMailingList": "mailingList3",
"projectImageUrl": "imageUrl3",
"projectCreationDate": "apr 29, 2019",
"projectVersion": 1
}];
}
}
我想在projectListId
上使用map函数来迭代projectId
。这就是我正在做的:
this.props.projectListId.data.map(projectId => {//do something})
在“做某事”中,我现在只是console.log projectId
,以了解它是否正确,但是返回未定义。
我在构造函数中检查了以这种方式传递的prop的正确性:
console.log("Test for map " + this.props.projectListId.data[0].projectVersion);
它工作正常。