This article introduces examples of ReactJS implementing single-choice and anti-choice forms. I will share them with you. I hope it will be helpful to you.
Requirements are to implement single-choice, anti-choice and multiple-choice on the list, and clear all
...... = { //Initialize the empty array to indicate that the selected selectedStores:[], } ...... handleClick(e){ const newSelection = ;//Get the specific item of click let newSelectionArray;// Create a new empty array //Display whether the click item is selected. If yes, clear the selected state if((newSelection) > -1) { newSelectionArray = ((s:any) => s !== newSelection) } else { //If not, add a new selection array newSelectionArray = [..., newSelection]; } ({ // Change the new selection array to selected state uniformly selectedStores: newSelectionArray }); }
The () method returns the first index where a given element can be found in the array, and if it does not exist, it returns -1.
grammar:
(searchElement) (searchElement[, fromIndex = 0])
The () method creates a new array containing all elements of the test implemented by the provided function.
grammar:
var new_array = (callback[, thisArg])
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.