如何使用 redux 操作数组的精确元素

How to manipulate precise element of an array with redux

今天,我尝试用 redux 制作一个列表,您可以在其中随意添加和删除元素 visible here。我的列表实际上是一个数组,每次用户单击 "Add to the list" 或 "Remove last added element" 时都会更新。

现在我想做一件事,但我不知道该怎么做。事实上,我想做的是,例如,如果用户再次尝试添加 Tristan,则带有 Tristan 的 FromControl 变为 'sucess'(我也使用 bootstrap),但我不知道如何实现准确地说是元素,因为如果我在我的 reducer 中使用了一个变量,并且我说我的 FromControl 的样式取决于这个变量的状态,那么每个 FormControl 都会变成 'sucess'.

在此先感谢您的帮助:) (也为我的英语水平感到抱歉)

您可以使用 Array.prototype.findIndex() 获取数组中元素的索引,然后从那里向上移动。

我也看到你在控制台中有很多警告,我建议你在 foreach 中的组件中添加 key 并将 setState 调用移动到 componentWillMount 或其他合适的地方。