gpt4 book ai didi

javascript - react-editext中 'onSave ()'函数如何传两个参数?

转载 作者:行者123 更新时间:2023-11-30 08:18:22 25 4
gpt4 key购买 nike

我使用这个库:https://www.npmjs.com/package/react-editext .

当我有

onSave = (val) => {
  console.log (val)
}

在 console.log 中我有一个可编辑的值。我也在尝试将 id 传递给 onSave

`onSave = (val, todoId) => {
  console.log (val, todoId)
} `

但这不起作用,第二个值是未定义。如何传递两个值?

此处演示:https://stackblitz.com/edit/react-btc2df

import EdiText from 'react-editext';

class Example extends Component {
constructor(props) {
super(props);

this.state = {
todos: [
{
"id": 1,
"title": "delectus aut autem",
"completed": false
},
{
"id": 2,
"title": "delectus aut autem",
"completed": false
}
]
}
}

onSave = (val, todoId) => {
console.log(val, todoId)
}

render () {
return (
<div className="container">
{this.state.todos.map((todo, index) => {
return <EdiText
key={todo.id}
type="text"
value={todo.title}
onSave={() => this.onSave(todo.id)}
/>
})}
</div>
)
}
}

最佳答案

你忘了传递之前的参数:

onSave={val => this.onSave(val , todo.id)}

关于javascript - react-editext中 'onSave ()'函数如何传两个参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57974471/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com