react-native - 如果其他反应原生
问题描述
我是新来的反应本地人。我已经创建了一个屏幕,我正在使用 if else 在这样的功能中。
constructor(props) {
super(props);
this.state={
phpid = ''
}
}
validateInputs = (event) => {
const data = this.props.route.params.data
const { phpid } = this.state;
if (data.retail_information_data[0] != '') {
phpid == data.retail_information_data[0].id
}else{
phpid == null
}
AsyncStorage.multiGet(["application_id", "created_by"]).then(response => {
console.log(phpid)
fetch('https://njdnfech/Android_API_CI/uploaddata/tffmerchant_retail_details?query=', {
body: JSON.stringify([{phpid : phpid}])
})
.then((returnValue) => returnValue.json())
.then(function(response) {
console.log(response)
return response.json();
}
但我得到 = data.retail_information_data[0] = null 或者让我们说空然后根据 if else 我的 else 条件是 'phpid == null' 应该运行,但即使是 'data.retail_information_data[0] = null' 我的 else 条件没有运行我的控制台kepp说'TypeError:undefined is not an object(评估'data.retail_information_data [0].id')'是我的if else中的任何问题,或者如何写正确if else
解决方案
尝试使用三元运算符。phpid = data.retail_information_data[0] ?data.retail_information_data[0].id:空
推荐阅读
- deep-learning - 深度纯价值强化学习:训练 V(s) 而不是 Q(s,a)?
- django - 带有设置子文件夹的 django wsgi 设置
- c# - Xamarin ios 自定义 WKWebview 渲染器默认解析 youtube 视频全屏显示
- python - 使用 Google 进行阿拉伯情绪分析
- javascript - 快速会话空会话
- html - 如何删除摘要元素侧面的箭头?
- cuda - CUDA 内核失败:没有可在设备上执行的内核映像,在 Google Compute VM 中运行 PyTorch 模型时出错
- websocket - 是否可以将 websocket 消息发送到 kafka 主题?
- amazon-web-services - 无法访问使用现有实例的映像创建的 AWS 实例
- java - JSch 没有检测到 $HOME/.ssh/id_rsa 公钥