0
我有一個顯示單選按鈕的React組件。這些變化應該由Reflux處理。據我瞭解,this.trigger(object)
應該被調用來保存對對象的任何更改。不幸的是,這會導致無限循環。React Reflux:onUpdate#this.trigger(rows)導致無限循環
我發佈了一個JSFiddle here來演示錯誤。 任何人都可以看到我做錯了什麼? onUpdateAutoComplete(checked)
應該如何製作?
<AutoCompleteFrom autocomplete_from={form_fields.autocomplete_from} />
CheckBox組件
var AutoCompleteFrom = React.createClass({
mixins: [Reflux.connect(store)],
render: function() {
var autocompleteFrom = this.props.autocomplete_from.map(function(value) {
return (
<label for={value}>
<input type="radio" name={'autocomplete_from'+this.props.id} value={value}
onChange={actions.updateAutoComplete(this.props.checked)}
checked={this.props.checked == value}
/>
{value}
</label>
);
}, this);
return (
<div className="autocomplete-from">
{autocompleteFrom}
</div>
);
}
});
onUpdateAutoComplete
onUpdateAutoComplete(checked){
console.log('checked:', checked);
rows[0].autocomplete_from = checked;
// this.trigger(rows); // <== Causes an infinite loop when included.
},
乾杯, 馬丁