0
我無法訪問通過道具傳遞給我的EditField組件的對象的鍵。當我記錄傳遞給控制檯的道具時,它會正確輸出對象,但是當我嘗試獲取該對象的任何鍵時,我會得到一個「未定義的錯誤」。這個對象是什麼?圖片上是做的console.log(部門),當我得到大家看看我的代碼的對象:無法訪問對象的屬性
class EditForm extends React.Component {
render() {
const departments = this.props.departments
const showcasedDepName = this.props.showcasedDepName
const dep = departments.filter(dep => dep.depName ===
showcasedDepName)[0]
return(
...irrelevant stuff
<EditField department={dep}/>
</form>
</div>
)
}
}
EditField中成分:
class EditField extends React.Component {
render() {
const department = this.props.department
console.log(department.depName) //"undefined", whereas it shows me the correct object when I do console.log(department)
return(
<div className="edit-dep">
<div>Department name: <input type="text" value=
{department.depName}/></div>
</div>
)
}
}
你可以添加對象的結構嗎?或者什麼在console.log(部門) –
添加到帖子 – Umbrella
嘗試console.log(部門[0] .depName) –