var data = 0;
NativeStorage.getItem('loginSession',(result)=>{
data = result;
},(err)=>{
console.log(err);
});
// I want here the new value of variable data
就像我在这里提到的,如何在函数末尾获取值。 因为因为我要从另一个请求此函数以获取该特定值。像这样
function a(){
var ntval = getmetheNativeValue();
console.log(ntval);
}
function getmetheNativeValue(){
var data = 0;
NativeStorage.getItem('loginSession',(result)=>{
data = result;
//And here if I try to return the data variable like return(data); not working as well
},(err)=>{
console.log(err);
});
//now here I need to return the new data value like this return(data); but this returning the old value as 0 not the new value.
}
请任何人告诉我如何从第二个函数中获取第一个函数的值?
这是我的asn函数,请检查我的方向是否正确
itemInCart:async(id)=>{
await NativeStorage.getItem('cartSession',(result)=>{
if(result==''){
returns= 0;
//return returns;
}else{
var split = result.split(';');
for(var i=0;i<split.length;i++){
var split_again = split[i].split('-');
if(split_again[0]==id){ console.log('true event');
returns= 1;
//return returns;
}
}
returns= 0;
//return returns;
}
},()=>{
returns= 0;
//return returns;
});
return returns;
}