Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/463.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 参照数组中的对象_Javascript_Reactjs - Fatal编程技术网

Javascript 参照数组中的对象

Javascript 参照数组中的对象,javascript,reactjs,Javascript,Reactjs,请说明如何引用(更改或删除)对象数组中的特定对象,例如 var myArray = [ {id: 1}, {id: 2}, {id: 3}, {id: 4} ] //initial state for number set as an array state = { number: [] } //a function which runs any time a button called create is clicked increment = () => { this.s

请说明如何引用(更改或删除)对象数组中的特定对象,例如

var myArray = [ {id: 1}, {id: 2}, {id: 3}, {id: 4} ]


//initial state for number set as an array
state = {
  number: []
}

//a function which runs any time a button called create is clicked
increment = () => {
  this.setState({
    numbers: [...this.state.number, {
      id: Date.now()
    }],
  })
}
//the array looks like this: number=[{id:53432},{id:34534},{id:434553}]

//the array is passed on to a component using the map function
{
  this.state.numbers.map(number => < Section key = {
        number.id
      }
      />)}
var myArray=[{id:1},{id:2},{id:3},{id:4}]
//设置为数组的数字的初始状态
状态={
编号:[]
}
//一个函数,可在单击名为“创建”的按钮时随时运行
增量=()=>{
这是我的国家({
编号:[…this.state.number{
id:Date.now()
}],
})
}
//数组如下所示:number=[{id:53432},{id:34534},{id:434553}]
//使用map函数将数组传递给组件
{
this.state.numbers.map(number=>
)}
部分
组件中,我有一个与数组的每个字段关联的按钮。 单击按钮时如何引用特定对象?例如,一个用于记录其按钮已按下的数组中对象的id的函数

var myArray=[{id:1},{id:2},{id:3},{id:4}]
var myArray = [ {id: 1}, {id: 2}, {id: 3}, {id: 4} ]
handleClick(id){
    console.log('clicked id is', id);
}
myArray.map((item) => {
    <Button onClick={ () => this.handleClick(item.id)} />
})
handleClick(id){ log('clicked id为',id); } myArray.map((项目)=>{ this.handleClick(item.id)}/> })
建议您学习一些基本的“todo”应用程序示例/教程,这些示例/教程可以在web上轻松找到。您询问的功能将包含在所有功能中。Stackoverflow并不是《感谢Anshul》中描述的“如何”教程服务。这让我知道了该怎么做