作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将一些数据发送到我的数据库,但这些数据也来 self 的数据库。通过按发送按钮,显示的项目/数据应发送/添加到数据库中。
我尝试使用 this.setState({ name: item.menu_desc })
但它给了我这个错误:
export default class Dishes extends Component {
constructor(props) {
super (props)
this.state = {
....
....
name: null,
menu_price: null,
}
}
submit = ({ item, index }) => {
this.setState({ name: item.menu_desc }); // my setStates
this.setState({ menu_price: item.menu_price });
fetch('http://192.168.***.***:3308/SendOrder/Send', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
....
menu_desc: item.menu_desc,
menu_price: item.menu_price,
})
}).then(res => res.json())
.then((responseJson) => {
Alert.alert(JSON.stringify(responseJson))
console.log(responseJson);
})
.catch(error => console.error('Error:', error))
}
return (
<View>
.....
<Text>Name: { item.menu_desc }</Text> // This is name
<Text>Price: ₱{ item.menu_price }</Text> // This is price
<Text>Status: { item.menu_status }</Text>
.....
<TouchableOpacity
onPress = {(item,index) => this.submit(item,index)}>
<Text>Send Order</Text>
</TouchableOpacity>
</View>
)
}
render() {
return (
<FlatList
data = {this.state.data}
keyExtractor={(item, index) => index.toString()}
extraData={this.state}
renderItem = {this._renderItem}
/>
</View>
)
}
}
最佳答案
您正在调用this.submit(item,index)
其中 item
是第一个变量,index
是第二个变量。但是提交函数尝试像这样解构项目对象。
提交 = ({ item, index }) => {
删除花括号或将参数作为对象发送。
关于javascript - React Native - 未定义不是对象(评估 'item.menu_desc' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51525285/
我正在尝试将一些数据发送到我的数据库,但这些数据也来 self 的数据库。通过按发送按钮,显示的项目/数据应发送/添加到数据库中。 我尝试使用 this.setState({ name: item.m
我是一名优秀的程序员,十分优秀!