我正在开发一个使用react native的应用程序,其中admin从后端添加了问题,而User回答了来自app的问题。 我正在从数据库表问题(qid,类别,问题)中获取问题
这是我的代码
this.state = {
users: [],
};
<ScrollView style={[{ flex: 1, zIndex: 0 }]} contentContainerStyle={[loading && { justifyContent: 'center', alignItems: 'center' }]}>
{loading && <Animated.View style={{ transform: [{ rotate: spin }] }}><Icon type="FontAwesome" name='spinner' color={colors.grayIcon} /></Animated.View>}
{
!loading &&
<View >
{this.createUI()}
<Button rounded block style={styles.button_submit} onPress={this.testsubmit}>
<Text>Submit</Text>
</Button>
</View>
}
</ScrollView>
</View>
</Form>
handleChange(i, e) {
const { testname, value } = e.target;
let users = [...this.state.users];
users[i] = {...users[i], [testname]: value};
this.setState({ users });
}
createUI(){
console.log("In Render:",this.state.users);
return this.state.users.map((el, i) => (
<View>
<Text>{el.cat}</Text>
<Item stackedLabel style={styles.text_item_style}>
<Label style={styles.label_style}>{el.name.toUpperCase()}</Label>
<Input style={styles.text_input} name={el.question} keyboardType="number-pad" onChange={this.handleChange.bind(this, i)}/>
</Item>
</View>
))
}