2017-07-30 60 views
0

這與基於admin-rest的reactJs框架有關。[admin-on-rest]:僅在搜索按鈕被按下時搜索

只有當按下搜索按鈕時,我需要一些關於啓用搜索的幫助/指針。我需要從用戶那裏收集多個輸入,並最終在單擊搜索按鈕時通過REST Api將查詢推送到後端。

查詢搜索非常大的數據庫集,並且我不想在用戶輸入時將查詢推送到後端。

回答

0

這是你需要做的。

您需要編寫一個自定義的Redux窗體組件。像下面的東西。我沒有測試過這個代碼。但我希望你能得到大致的想法。您還需要處理Redux Form傳遞給組件的所有道具。看看Redux表格文檔。還可以看看源代碼中的Rest-On的TextInput組件。

const ENTER_KEY = 13; 

class RenderTextField extends Component { 
    handleKeyDown = (event) => { 
     switch(event.keyCode) { 
     case ENTER_KEY: 
      this.props.input.onChange(this.state.searchQuery); 
      break; 
     default: 
      this.setState({this.searchQuery: event.target.value}) 
    } 
    } 
    render() { 
    return (<input onKeyDown={this.handleKeyDown} 
     //You will need to look at the ReduxForm docs and handle all the props that are passed to every ReduxForm component. 
    />) 
    } 
} 

4)您也可以在ReduxForm中使用材質UI組件。

http://redux-form.com/6.0.0-rc.1/examples/material-ui/