以下は、私がのgetType()メソッドを使用して選択ボックス(SelectAccountフィールド)での動的なオプションを生成しています私のコード未定義は
class ApplyForm extends Component {
constructor(props) {
super(props);
this.getType = this.getType.bind(this);
this.state = {
accessToken: '',
accountsComapny: '',
type: this.getType(),
};
}
async componentDidMount() {
await this.getToken();
const token = 'Token ' + this.state.accessToken;
this.loadAccountsComapnyData(token);
}
getType() {
if (this.state.accountsComapny) { // Error Line
AccountsList = t.enums(this.state.accountsComapny.accounts);
}
return t.struct({
amount: t.Number,
Purpose: LoanPurpose,
Time: t.Number,
Frequency: Frequency,
FirstPayment: t.Date,
SelectAccount: AccountsList
});
}
render() {
return (
<Container theme={theme} style={styles.bg} >
<Content >
<View style={styles.TransactionFormcontainer}>
<Form
ref="form"
type={this.state.type}
options={options}
/>
<Button
rounded primary block
onPress={this.createNewLoan.bind(this)}
style={styles.submitBtn} textStyle={{ fontSize: 17 }}
>
Apply
</Button>
</View>
</Content>
</Image>
</Container>
);
}
}
あるコンストラクタ()メソッドでのオブジェクトではありません。
しかし、コンストラクタメソッドでgetType()を呼び出すと、以下のエラーがスローされます。
未定義あなたが
this.state
オブジェクトを作成getType()
を使用し、getType()
にあなたがそれにアクセスするためにwan't( 'this.state.accountsComapny' を評価)オブジェクト