Loop through form checkboxes for dynamic list of checkboxes
Date : March 29 2020, 07:55 AM
Hope that helps , So you want all inputs whose ids start with cbProducts? $("form input[id^='cbProducts']");
_ctl = $("form input[id*='cbProducts']");
$("form input[id='cbProducts' + elm]");
$("#cbProducts" + elm);
|
react setState with dynamic key
Date : March 29 2020, 07:55 AM
wish of those help Basic rule is: We can use Computed property names concept and use any js expression to compute the object property name dynamically. For that we need to put the expression inside []. var obj = {
[10 * 20 + 1 - 5]: "Hello"
};
console.log('obj = ', obj);
onChange(e) {
this.setState({
[e.target.id]: e.target.value
})
}
onChange(e) {
let obj = {};
obj[e.target.id] = e.target.value
this.setState(obj);
}
|
react native dynamic setstate with string and dynamic index
Date : March 29 2020, 07:55 AM
may help you . For React Native to detect changes to state and thus re-render your view you must call setState in immutable manner. So in your case try the following: //copy state
const newState = {...this.state};
//access property - "key1, key2, etc" whatever index is.
newState['key'+index] = 1;
// set new state
this.setState(newState);
|
Using a dynamic key to setState in React
Date : March 29 2020, 07:55 AM
Does that help When setting state with a dynamic key, you need to wrap the key within [] like <Modal
onTextChange={(text, key) => {
this.setState({
event: {
[key]: text
}
})
}}
/>
|
dynamic setState to add new dynamic property in react
Date : March 29 2020, 07:55 AM
it should still fix some issue If I understood what you're trying to do correctly, you just needed to spread the value object inside of your map: onChange = (e, i) => {
this.setState({
items: this.state.items.map(o => ({
...o,
value: {
...o.value, // <- this
[this.state.lang[i]]: e.target.value
}
}))
});
};
|