javascript - ReactJs: How to update property of state -
i trying update isselected property row of data stored in state, property doesn't update can please tell me best way this?
var selectedidspush = []; var selectedidspush = this.state.contacts.slice(); for(var i=0;i<selectedidspush.length;i++) { var idasnumber = parseint(id); if (page.state.contacts[i].id === idasnumber) { page.state.contacts[i].isselected = true; break; } }
reacts wants consumers setstate
instead of assigning properties directly. in example, build , assign new contacts
list using:
var idasnumber = parseint(id); var newcontacts = this.state.contacts.map(function (contact) { if (contact.id === idasnumber) { contact.isselected = true; } return contact; }); this.setstate({ contacts: newcontacts });
Comments
Post a Comment