2017-01-24 23 views
5

3秒演示https://www.youtube.com/watch?v=bo2nNQXbhI8&feature=youtu.be所選擇的選項將被恢復到未選擇的狀態

https://gist.github.com/weichenghsu/407a8862f3382a425fb531b3dedcd6f5

作爲標題,所選擇的選項將被恢復到未選擇的狀態 image

而且onChange方法具有用於無影響官方教程示例。

我的用例是,當用戶從下拉列表中選擇一個值。它應該解僱的行動來獲取其他數據並呈現另一種形式的

const chooseTable = ({items, meta:{touched, error}}) => (
      <select 
       onChange={event => { 
        console.log(this.props.fields); 
        this.props.tableNameOnChange(event.target.value); 
      }}> 
       <option value="">Select</option> 
       { 

        items.map((item :any, i: integer) => 
         <option key={item.id} value={item.id}>{item.name}</option> 
        ) 
       } 
      </select> 
    ) 

        <Field component={chooseTable} 
          items={schemaData.tableList} 
          name="tableName" 

        > 
         {/*<option value="#ff0000">Red</option>*/} 
         {/*<option value="#00ff00">Green</option>*/} 
         {/*<option value="#0000ff">Blue</option>*/} 
        </Field> 

      UIBuilderForm = reduxForm({ 
       form: 'dashbaordUiBuilderForm', 
       fields: ['tableName'] 
      } 
      }) 
      (UIBuilderForm as any); 

      // Decorate with connect to read form values 
      const selector = formValueSelector('dashbaordUiBuilderForm') 

      // export default connect(mapStateToProps, mapDispatchToProps)(UIBuilderForm); 
      export default connect(state => { 
       const TableSchemaName = selector(state, 'TableSchemaName') 
       return { 
        TableSchemaName 
       } 
      } 
+0

Redux表格''要求您使用各種道具[如此處所述](http://redux-form.com/6.4.3/docs/api/Field.md/)。 – gustavohenke

+0

沒有用,調度動作仍然不起作用onChange方法 – newBike

回答

1

我敲我的腦袋上一個類似的問題與反應本地選擇器。嘗試將'chooseTable'作爲組件而不是無狀態函數編寫,並使用'this.state'和'this.setState'來引用選擇的值。這裏有一個例子從我選擇器代碼:

class ExpirePicker extends React.Component { 
    constructor(props) { 
    super(props) 

    this.state = { 
     selected: 'ASAP' 
    } 
    } 

    render() { 
    const { input: { onChange, ...rest }} = this.props 
    return (
     <Picker 
     style={style.input} 
     selectedValue={this.state.selected} 
     onValueChange={(value) => { 
      this.setState({selected: value}) 
      onChange(value) 
     }} 
     {...rest}> 
     {Object.keys(ExpireTypes).map(renderItem)} 
     </Picker> 
    ) 
    } 
} 

你能也可以使用元素的「的onChange」事件,它不綁定到終極版 - 形式「的onChange」道具?