我是新的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