안녕하세요, PUT 방식을 rest-server 형식에 맞춰서 넣었을때는 데이터가 바뀌었습니다.
fetchGradeUpdate() {
return fetch(`http://192.168.190.16:3000/api/Grade/1`,
{
headers: {
'Accept': 'application/json',
"date": "Thu, 10 Jan 2019 03:00:17 GMT",
"x-content-type-options": "nosniff",
"etag": "W/\"e2-kYVVz5gED3yKO/9HE+gjuOt5AZ4\"",
"x-download-options": "noopen",
"x-frame-options": "DENY",
"Content-type": "application/json; charset=utf-8",
"access-control-allow-origin": "http://localhost:3000",
"access-control-allow-credentials": "true",
"connection": "keep-alive",
"vary": "Origin, Accept-Encoding",
"content-length": "226",
"x-xss-protection": "1; mode=block"
},
method: 'PUT',
body: JSON.stringify({
$class: "org.acme.model.Grade",
safetycheck_date: "2019.01.10",
admin: "resource:org.acme.model.User#a@naver.com",
Electricity: "Green",
Gas: "Green",
Elevator: "Green",
Earthquake_resistant: "Green",
Final: "Green"
})
})
.then(response => {
response.json(),
console.log(response.json())
})
.catch(error => {
console.error(error);
});

그런데, body안의 내용을 this.state로 바꾸고 render 함수에서 TextInput 라이브러리를 써서 onChangeText에 setState를 함으로서 데이터를 바꾸었을 때는 데이터가 넘어가지가 않습니다.
return fetch(`http://192.168.190.16:3000/api/Grade/${facilityNumber_prev}`,
{
headers: {
'Accept': 'application/json',
"date": "Thu, 10 Jan 2019 03:00:17 GMT",
"x-content-type-options": "nosniff",
"etag": "W/\"e2-kYVVz5gED3yKO/9HE+gjuOt5AZ4\"",
"x-download-options": "noopen",
"x-frame-options": "DENY",
"Content-type": "application/json; charset=utf-8",
"access-control-allow-origin": "http://localhost:3000",
"access-control-allow-credentials": "true",
"connection": "keep-alive",
"vary": "Origin, Accept-Encoding",
"content-length": "226",
"x-xss-protection": "1; mode=block"
},
method: 'PUT',
body: JSON.stringify({
$class: "org.acme.model.Grade",
safetycheck_date: this.state.safetycheck_date,
admin: "resource:org.acme.model.User#a@naver.com",
Electricity: this.state.Electricity,
Gas: this.state.Gas,
Elevator: this.state.Elvator,
Earthquake_resistant: this.state.Earthquake_resistant,
Final: this.state.Final
})
})
.then(response => {
response.json(),
console.log(response.json())
})
.catch(error => {
console.error(error);
});
render() {
return(
<View style={styles1.container}>
<View Update Electricity ></View>
<Text>safetycheck_date_update</Text>
<TextInput
value={this.state.safetycheck_date} onChangeText={(text) => { this.setState({ safetycheck_date : text }) }}></TextInput>
<Text>Electricity_Grade_update</Text>
<TextInput
value={this.state.Electricity} onChangeText={(text) => { this.setState({ Electricity : text }) }}></TextInput>
<TextInput
value={this.state.Gas} onChangeText={(text) => { this.setState({ Gas : text }) }}></TextInput>
<TextInput
value={this.state.Elevator} onChangeText={(text) => { this.setState({ Elevator : text }) }}></TextInput>
<TextInput
value={this.state.Earthquake_resistant} onChangeText={(text) => { this.setState({ Earthquake_resistant : text }) }}></TextInput>
<TextInput
value={this.state.Final} onChangeText={(text) => { this.setState({ Final : text }) }}></TextInput>
<Button title="+ GradeUpdate"
onPress={() => { this.fetchGradeUpdate().then(() => { this.props.navigation.navigate('GradeScreen') }) }}>
</Button>
</View>
Put방식으로 데이터를 바꿀 때는 TextInput으로 onChangeText를 쓰면 안되는건가요? 다른 handleChange를 써야하는지… 잘 모르겠습니다 ㅠ
fetch 함수 안 json response 에러는 [Unhandled promise rejection: TypeError: Already read] 이라고 뜹니다. 이종은 강사님 말씀대로 Type Error인거 같은데 어떤게 문제인지…ㅠ