这是代码块:
export function ViewHeaders(props){
console.log(props.pitches)
return (
props.pitchKeys.map((pitchKey, index) => {
console.log(pitchKey)
//prints as expected
return (
<div>
<h1> {pitchKey} </h1>
<ViewPitches pitches={props.pitches} key={pitchKey}/>
</div>
)
})
)
};
function ViewPitches(props) {
console.log(props.key)
// printing as undefined
return(
props.pitches.map((pitch, index) => {
if (pitch.pitchName == props.key) {
return (<div>{pitch.id}</div>)
}
})
)
}
Run Code Online (Sandbox Code Playgroud)
我正在迭代一个列表props.pitchKeys并在内部按预期ViewHeaders打印出来pitchKey.
然后我pitchKey作为道具进入ViewPitches.
但是,当我打印出来时,props.key它会以未定义的形式返回.将.map()的返回值传递给props时,是否必须执行一些特殊操作?
| 归档时间: |
|
| 查看次数: |
341 次 |
| 最近记录: |