所以我得到了App
哪个实现了componentDidMount
and render
。
App 包含 2 个组件,一个是AutoComplete
输入,另一个是CardView
.
计划是一旦用户从AutoComplete
列表中选择了一个项目,将其显示在CardView
我想知道如何CardView
从AutoComplete
事件处理程序中触发 ' 渲染(即设置它的状态)。
请参阅以下内容:
// 愿意在这里触发 CardView 的渲染。
在下面的代码中。
import React, { Component } from 'react';
import injectTapEventPlugin from 'react-tap-event-plugin';
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
import AutoComplete from 'material-ui/AutoComplete';
// Needed for onTouchTap
// http://stackoverflow.com/a/34015469/988941
injectTapEventPlugin();
import './App.css';
class App extends Component {
constructor () {
super();
this.state = {accounts: []}
this.showAccount = this.showAccount.bind(this);
}
componentDidMount() {
this.setState({ accounts: [
{account_name: "foo", account_id: 1},
{account_name: "bar", account_id: 2}
]})
}
showAccount (value) {
// willing to trigger CardView's render right here.
}
render() {
return (
<MuiThemeProvider>
<div className="App">
<center>
<AutoComplete
floatingLabelText="account name"
filter={AutoComplete.caseInsensitiveFilter}
dataSource={this.state.accounts.map((account) => account.account_name)}
onUpdateInput={this.showAccount}
/></center>
<CardView />
</div>
</MuiThemeProvider>
);
}
}
export default App;