如何使用react更新数组中的项目?

时间:2017-01-02 05:01:07

标签: reactjs redux react-redux

您能告诉我如何使用react更新数组中的项目吗?我使用add按钮制作动态列表。在生成的项目中,我有两个按钮updatedelete。 点击更新按钮后,我将添加按钮的文本更改为update,并在输入字段中填写所选值。现在,当我单击更新按钮时,我想更新所选项目。

这是我的代码 https://plnkr.co/edit/bpSGPLLoDZcofV4DYxPe?p=preview

  addName() {
    if (this.state.username !== '') {
        if (this.state.btnText === 'add') {
            this.props.add(this.state.username)
        } else if (this.state.btnText === 'update') {
            this.props.updateItem(this.state.username)
        }
        this.setState({
            username: '',
            btnText: 'add'
        })
    }
}
delete(item) {
    this.props.deleteItem(item)
}
  update(item){
     this.setState({
      username : item,
      btnText:'update'
    })
  }

1 个答案:

答案 0 :(得分:0)

您需要将更新的项目名称和项目索引传递给reducer中的更新案例。然后只需使用splice来更新新值

更新了plunkr。检查here

Dim appProgID As String = "Autocad.Application"
Dim fname As String = "C:\Users\Kid\Downloads\IDEA FOR TOOL\TEST\TABLE ATTRIBUTE.dwg"

Dim AcadType As Type = Type.GetTypeFromProgID(appProgID)


Dim AcadApp As Object = Activator.CreateInstance(AcadType)
Dim visargs() As Object = New Object(0) {}
visargs(0) = False
 AcadApp.GetType().InvokeMember("Visible", BindingFlags.SetProperty, Nothing, AcadApp, visargs, Nothing)
Dim AcadDocs As Object = AcadApp.GetType().InvokeMember(
"Documents", BindingFlags.GetProperty, Nothing, AcadApp, Nothing)


Dim args() As Object = New Object(1) {}
args(0) = fname
args(1) = False

 Dim AcDoc As Object = AcadDocs.GetType.InvokeMember(
    "Open", BindingFlags.InvokeMethod, Nothing, AcadDocs, args, Nothing)

AcadApp.GetType.InvokeMember(
    "ActiveDocument", BindingFlags.GetProperty, Nothing, AcadApp, Nothing, Nothing)

 AcDoc = AcadApp.GetType.InvokeMember(
"ActiveDocument", BindingFlags.GetProperty, Nothing, AcadApp, Nothing, Nothing)


Dim AcadModel As Object = AcDoc.GetType.InvokeMember("modelspace", BindingFlags.GetProperty, Nothing, AcDoc, Nothing)
Dim entity As Object
For Each entity In AcadModel
If TypeName(entity) = "IAcadBlockReference" Then
'here i want to take this block has name "tab1"       
End If
Next