2017-07-30 57 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/