【问题标题】:React Reflux: onUpdate#this.trigger(rows) causes an infinite loopReact Reflux:onUpdate#this.trigger(rows) 导致无限循环
【发布时间】:2015-06-19 23:13:41
【问题描述】:

我有一个显示单选按钮的 React 组件。对这些的更改应由 Reflux 处理。据我了解,应该调用this.trigger(object) 来保存对对象的任何更改。不幸的是,这会导致无限循环。

我已经发布了一个 JSFiddle here 来演示该错误。 谁能看到我做错了什么? onUpdateAutoComplete(checked)应该如何制作?

<AutoCompleteFrom autocomplete_from={form_fields.autocomplete_from} />

复选框组件

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.
  },

干杯, 马丁

【问题讨论】:

    标签: javascript reactjs refluxjs


    【解决方案1】:

    解决方法是调用onChange={actions.handleChange} 并触发actions.updateAutoComplete(event.target.value, event.target.name);

    Fiddle 已更新为工作代码。

    【讨论】:

      猜你喜欢
      • 2021-11-01
      • 2021-02-13
      • 2021-02-19
      • 2018-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-27
      • 2021-05-07
      相关资源
      最近更新 更多