こんにちは(私は子どもの親のコミュニケーションのシステムを採用して、私のReactアプリケーションのページの1つでは、私はオン/オフを切り替えることができるように、これらの変更を別のページにまたがって維持できるようにするために、いくつかの「スイッチ」オブジェクトを用意したいと思っています。 :Javascript - 子どもの状態の変化が親に残っていない
は私の親の状態を作成します。
class dashboard extends Component { constructor(props) { super(props); this.updateObject.bind(this); } state = { test_dictionary: {'test': false} };
DEFIを上記の状態を更新する親内の関数。
updateObject(current_key) { var new_state = Object.assign({}, this.state.test_dictionary); new_state[current_key] = !new_state[current_key]; // I want to flip the boolean when clicked this.setState({test_dictionary: new_state}); }
次に、状態と機能(上に示した)を親から子に渡します。
<childView test_dictionary={this.state.test_dictionary} updateObject={this.updateObject}/>
最後に、かつて私は、私が機能し、毎回内のスイッチオブジェクトが変更された親の状態で辞書を更新するために渡された状態を使用しようと、子の内側です。
<Switch checked={this.props.test_dictionary['test']} onChange={this.props.updateObject.bind('test')} />
しかし、これは私はそれが何を期待する何をしていません。私は子どもの親のコミュニケーションを設定する方法の数多くの異なる例を読んでみることにしました。
Uncaught TypeError: Cannot read property 'updateObject' of undefined
at String.handleSelectionChange (childView?9911:28)
at String.handleSelectionChange (createPrototypeProxy.js?9d62b87:44)
at Switch.setChecked (Switch.js?bc7e1ee:54)
at toggle (Switch.js?bc7e1ee:105)
at Object.ReactErrorUtils.invokeGuardedCallback (ReactErrorUtils.js?c23a69d:69)
at executeDispatch (EventPluginUtils.js?46a03e1:85)
at Object.executeDispatchesInOrder (EventPluginUtils.js?46a03e1:105)
at executeDispatchesAndRelease (EventPluginHub.js?2c8fe93:43)
at executeDispatchesAndReleaseTopLevel (EventPluginHub.js?2c8fe93:54)
at Array.forEach (<anonymous>)
私はあなたが提供できる任意のヘルプをお願い申し上げます
フィードバックをいただきありがとうございます。 'Uncaught TypeError:Uncaught TypeErrorの代わりに 'undefined'の' test_dictionary 'プロパティを読み込めません:' undefined'のupdateObject 'プロパティを読み込めません。これから、私は 'updateObject'関数の中で私がアクセスしようとしている' this.state.test_dictionary'に到達できないと仮定しています。それ以上の提案はありますか?私は本当にあなたの助けに感謝します! –