score:-1
it looks like the only difference you are talking about making is using an array of objects instead of strings? if that's the case, when looping through the array to create the checkboxes, you access the object attributes using dot notation. it should look something like this if i understand the problem correctly.
from checkboxgroup component:
this.props.options.foreach(el => {
let name = el.name;
let id = el.id;
//rest of code to create checkboxes
or to show an example in creating components
let checkboxmarkup = [];
checkboxmarkup.push(
<input type="checkbox" id={el.id} name={el.name} key={`${el.id} - ${el.name}`}/>
);
}
'el' in this case refers to each individual object when looping through the array. it's not necessary to assign it to a variable, i just used that to show an example of how to access the properties.
score:0
problem solved. i should use "use with grid" type of group checkbox. it accepts object array. the only think i could do was creating a function that inject "label" and "value" to my object. it makes some duplicates but no problem.
function groupecheckboxify(obj, labelfrom) {
for (var i = 0; i < obj.length; i++) {
if (obj[i][labelfrom]) {
obj[i]['label'] = obj[i][labelfrom];
obj[i]['value'] = obj[i][labelfrom];
}
if (i == obj.length - 1) {
return obj;
}
}
}
// for calling it:
groupecheckboxify( myobject , 'name');
Source: stackoverflow.com
Related Query
- Group checkbox in Antd by using array object
- Data object with array of different groups, trying to display ordered by group type using .map() and pushing to new array nothing is rendering
- Removing object from array using hooks (useState)
- Updating the array object in React state using immutability helper
- Add object to the beginning of array using spread operator
- How to delete object from array using object property - React
- React/Redux - Add object to start of array using spread operator
- How to push into an array of object using the spread operator to a specific element
- react setState array of object using map doesn't work?
- React Formik checkbox group does not turn into an array of invidual checked or unchecked elements
- How to update an object in an array of Objects using setState
- React js useState hook. How to update state of a json object with an a array in it when a checkbox is clicked
- update the array of object using useState hook
- How to send array of object in post request using axios library
- How to reduce and get value from object array using javascript
- Update a single property of object from array using useState() hook
- updating object inside array inside object using prevState and the useState hook
- React how to conditionally edit or add object in array of objects using setState
- Update array object object value using spread operator
- How to change an object value of a state array by using a specific array index
- update array of object and setState using shorthand
- Get object array from axios and using return value call another axios function and append the output to first result
- updating a property in an array of object immutably using react hooks
- Push object in array when checkbox is checked and remove object when checkbox is unchecked in ReactJS
- update array without object using map
- Reactjs - add/remove item from array and store using checkbox
- How to use spread operator to delete an object from array of objects using spread operator using react?
- how do i update state in react for updating the value of an object inside an array using array.map function
- Access Object in Array in React Using Immutable.js
- import of css using webpack returns an array not object
More Query from same tag
- How to transform: translate element through whole screen on Android?
- Using bind(this) in React
- How to use external filter with React? (ag-grid)
- Setting initial center for map from Web API on a React / google-maps-react component
- How would I set up audio streaming from a Node server to React frontend?
- How to deploy Node.js / React application to Heroku using Babel when writing ES6 code?
- Axios put request and symfony controller
- react-router - Cannot get information in this.props.location
- How to create a list of youtube components on React.js
- Svg animations not running on Safari
- React child component state updates parent component state
- Duplicate entries inside array of objects: Javascript
- Styling selected TreeItem inside a TreeView
- Input tag not rendering in React
- reactjs - Import a dynamic file in render() method
- Change color InputLabel Material UI
- React error "Uncaught Invariant Violation" when using react-router
- How to highlight navbar links on page scroll in React
- unable to replace process.env.hostname in axios post method
- Monaco editor in react app with language server for python intellisense
- Font settings not picked up in NextJS/React
- Why I have infity loop in useEffect when I use websocket?
- React and redux, modular editing of object hierarchy and REST api
- styled-components content condition doesn't work
- How do I change this.state of a component from parent?
- How do you map json in React?
- What does this syntax mean export default connect(mapStatetoProps, mapDispatchToProps)(LandingComponent)
- Setting React hooks state before function call
- Error of context consumer rendered with multiple children
- React application router