0
コンポーネントを使用してラジオボタンを作成していますが、ボタンはうまく構築されていますが、onPressは機能しません。ラジオボタンをクリックすると、タイトルにエラーが表示されます。私はこのエラーに基づいて、「これは私が思うものではない」と疑います。どんな助けもありがとうございます。私RadioBtn.jsファイルで次に未定義はオブジェクトではありません( '_this2.onRadioPressed'を評価しています)
let radio_props = [
{label: 'forward', value: 0 },
{label: 'back', value: 1 }
];
<RadioBtn
radioGroupLabel={'Main Label'}
radioLabels={radio_props}
style={styles.radioElement}>
</RadioBtn>
...
onRadioPressed =(val)で=> { はconsole.log( 'VAL::'、val)でここに関連するコードです。 this.setState({selectedValue:val}); };
renderRadios(obj, i) { console.log('OBJ:', obj); return ( <View style={styles.firstRadioContainer}> <TouchableOpacity onPress={(value, index) => { this.onRadioPressed(obj.value) }} underlayColor='#f1c40f'> <Text value={obj.value} style={styles.radio}>{obj.label}</Text> </TouchableOpacity> </View> ) }; render() { let renderedRadios = this.props.radioLabels.map(this.renderRadios); return ( <View> <View style={styles.radioLabelContainer}> <Text style={styles.radioLabel}>{this.props.radioGroupLabel}</Text> </View> <View style={styles.radioGrp}> {renderedRadios} </View> </View> ); };
パーフェクト。どうもありがとうございました! – miarde
あなたは大歓迎です。 –