在这里,我从api中获取数据,这是我的平面代码数据加载的视图代码
this.state = {
data: [],
//data_local: data_local,
radio_props: radio_props,
animating: true
//test_data:test_data,
};
<FlatList
data={this.state.data}
showsVerticalScrollIndicator={false}
renderItem={({ item }) => (
<View
style={{
flex: 1,
flexDirection: "row",
height: 50,
backgroundColor: "#D1F2EB",
borderRadius: 4,
borderWidth: 1,
borderColor: "#008000",
marginLeft: "1%"
}}
>
<Text
style={{
flex: 2,
fontSize: 19,
justifyContent: "space-between",
width: 150
}}
>
{item.rollno}--{item.name}
</Text>
<RadioForm
style={{
flex: 1,
flexDirection: "row",
padding: 10,
width: 30
}}
radio_props={radio_props}
initial={0}
onPress={value => {
this.setState({ value: value });
}}
ItemSeparatorComponent={this.renderSeparator}
/>
</View>
)}
// keyExtractor={(x, i) => i}
keyExtractor={(item, index) => index.toString()}
/>
<Button title="Submit" onPress={() => this.insert()} />
</View>
现在,我要发布所有这些列表数据。请注意,我只能发布一个数据,而且这是静态的。我如何逐行发布所有这些数据。 这是我的代码,仅发布一个数据
insert = () => {
/* */
//alert(this.state.username);
fetch("http://192.168.1.139:8082/Attendence/add", {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json"
},
body: JSON.stringify({
"rollno": "1170",
"typeofattendence": 0
})
})
.then(response => response.json())
.then(res => {
if (res.success === true) {
alert(res.message);
} else {
alert(res.message);
}
})
.catch(error => {
console.error(error);
});
};
请帮助我。谢谢