4
在ReactJS中更新数组中对象的最佳方法是什么?
如果您将数组作为状态的一部分,并且该数组包含对象,那么通过更改其中一个对象来更新状态的简便方法是什么? 示例,从关于react的教程中修改而来: var CommentBox = React.createClass({ getInitialState: function() { return {data: [ { id: 1, author: "john", text: "foo" }, { id: 2, author: "bob", text: "bar" } ]}; }, handleCommentEdit: function(id, text) { var existingComment = this.state.data.filter({ function(c) { c.id == id; }).first(); var updatedComments = ??; // not …