我是新的reactJS,並反應原生。我需要建議。 我很難理解如何創建列表元素的工作行爲。如何更改列表中的元素後點擊它
所以。我有父組件,它在scrollView中創建任務。
<ScrollView>
{this.state.tasks.map(function(ele) {
return (
<Task
action={this.handler}
key={ele.id}
title={ele.title}
subtitle={ele.subtitle}
state={ele.state}
/>
);
})}
</ScrollView>
我父組件具有狀態變量任務構造定義。
this.state = {
tasks: [
{ title: "A1", subtitle: "xyz", state: 0, id: 0 },
{ title: "A2", subtitle: "zyx", state: 0, id: 1 }]
}
如果點擊特定的任務,我想將狀態更改爲1。我試圖通過這樣做達到:https://ourcodeworld.com/articles/read/409/how-to-update-parent-state-from-child-component-in-react 但是,這是行不通的。
需要查看更多代碼 - 爲方便起見,這是一種縮寫格式嗎?處理程序在ScrollView組件中聲明在哪裏? – Mikkel
@Mikkel除此之外沒有太多的代碼,我應該粘貼子代碼(Task)組件,還是我的「搞亂解決方案」版本? – Yurrili