【发布时间】:2020-07-14 15:59:51
【问题描述】:
嘿,我在 react native 方面还是个新手……我正在尝试使用以下函数从 AsyncStorage 中获取价值。并尝试在警报中检索它。但我一直收到价值[对象对象]。在控制台日志上它可以显示该值,但一旦返回它就变成了对象。我可以知道为什么吗?
下面是我的功能..
_DeviceDetails = async (device) =>{
try {
let nonObj = 'hai'
const obj = await AsyncStorage.getItem(device)
let obj1 = JSON.parse(obj)
var devid = obj1.deviceId
var devnam = obj1.deviceName
var devdesc = obj1.deviceDesc
//console.log(obj + 'ads')
//return obj1.deviceName.toString;
console.log('-1-' + devid)
console.log('-2-' + devnam)
console.log('-3-' + devdesc)
return devnam
} catch (e) {
console.log('Failed to fetch the data from storage' + e);
}
}
以下是我的提醒...
<TouchableHighlight
style={{ backgroundColor: 'blue', justifyContent: 'center' , alignContent:'center'}}
activeOpacity={0.9}
underlayColor="pink" onPress={() =>
alert(item + ' - ' + (this._DeviceDetails(item)))}>
<Text style={{
fontSize: 15,
textAlign: 'center',
marginBottom: 16,
color: 'white'
}}>{item}</Text>
</TouchableHighlight>
【问题讨论】:
标签: react-native object asyncstorage