I have a mapping function which shows JSON values into checkboxes, I'm tried to add the children of these values as checkboxes under the current checkboxes, and it worked fine, but what i am trying to do now is make the show the 2 children checkbox once the parent checkbox is clicked.
I have Side Collection 1 and under it there is children (side 1 and side 2), what I tried but couldn't do is show (side 1 and side 2 checkboxes) once (Side Collection 1 checkbox) is checked, the checkbox values are passed as props from Checkbox.js to Itemlist.js where the fetch/map happens. Would Appreciate it if anyone can explain or demonstrate how this can be achieved.
Live Snippet: https://codesandbox.io/embed/5w8vwwmn5p?fontsize=14
Checkbox.js
class Checkboxes extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<form className="form">
<div>
<h2>{this.props.title}</h2>
<div className="inputGroup">
<input
id={this.props.childk + this.props.name}
name="checkbox"
type="checkbox"
/>
<label htmlFor={this.props.childk + this.props.name}>
{this.props.name}{" "}
</label>
</div>{" "}
{this.props.options &&
this.props.options.map(item => {
return (
<div className="inputGroup2">
{" "}
<div className="inputGroup">
<input
id={this.props.childk + (item.name || item.description)}
name="checkbox"
type="checkbox"
/>
<label
htmlFor={
this.props.childk + (item.name || item.description)
}
>
{item.name || item.description}{" "}
{/** <img src={this.props.img} alt="" /> <span className="pricemod">{props.childprice} SAR</span>
*/}
</label>
</div>
</div>
);
})}
</div>
</form>
);
}
}
export default Checkboxes;
Itemlist.js
...
<div>
{selectedMod &&
selectedMod.children &&
selectedMod.children.map((item, index) => (
<Checkboxes
key={index}
name={item.name || item.description}
myKey={index}
options={item.children}
childk={item.id}
limit={item.max}
/>
))}
</div>
...
Aucun commentaire:
Enregistrer un commentaire