Javascript 存储在AsyncStorage中的对象中的值不递增

Javascript 存储在AsyncStorage中的对象中的值不递增,javascript,reactjs,react-native,asynchronous,firebase-storage,Javascript,Reactjs,React Native,Asynchronous,Firebase Storage,我使用AsyncStorage存储一个对象,该对象将用于确定何时显示分级库。每次调用函数时,我所要做的就是增加Rating_Count键+1。在下面的代码中,else语句即使在第一次调用函数后仍保持运行。 log(TEST)显示分级计数的值为0。 如果我随后将If条件更改为testStorage1!==无效的 console.log(OH NO)的分级计数为NaN,但console.log(TEST)显示分级计数为0 consttestfunction=async()=>{ var testS

我使用AsyncStorage存储一个对象,该对象将用于确定何时显示分级库。每次调用函数时,我所要做的就是增加Rating_Count键+1。在下面的代码中,else语句即使在第一次调用函数后仍保持运行。 log(TEST)显示分级计数的值为0。 如果我随后将If条件更改为testStorage1!==无效的 console.log(OH NO)的分级计数为NaN,但console.log(TEST)显示分级计数为0

consttestfunction=async()=>{
var testStorage1=await AsyncStorage.getItem(在应用程序中\u评级\u计数)
testStorage1=JSON.parse(testStorage1);
log('TEST',testStorage1);
常量testObject={
评级计数:testStorage1.Rating计数=0){
AsyncStorage.getItem(应用程序中的分级计数)
.然后((testStorage)=>{
testStorage=JSON.parse(testStorage);
testStorage.Rating_count++;
AsyncStorage.setItem(在应用程序中,JSON.stringify(testStorage));
log('OH NO!',testStorage);
})
.catch((错误)=>{console.log(错误)});
}否则{
AsyncStorage.getItem(应用程序中的分级计数)
.然后((testStorage)=>{
testStorage=JSON.parse(testStorage);
testStorage.Rating_count=0;
AsyncStorage.setItem(在应用程序中,JSON.stringify(testStorage));
console.log('YESS',testStorage);
})
.catch((错误)=>{console.log(错误)});
}

}
将.Rating\u计数添加到testObject。 最初,我将整个AsyncStorage对象传递给密钥计数。 结束原始对象

常量testObject={ 评级计数:testStorage1.Rating计数, 评级日期:时刻()
}

您可以尝试使then函数异步,然后使关键字为'wait'的AsyncStorage.setItems行异步吗?不,这不起作用。仍然运行'0'的else正在保存,if正在运行,但它与主if语句中的某些内容有关,因为它注销NaN以获得评级。\u count所以有问题的行是testStorage.Rating_count++不起作用。我尝试了testStorage.Rating\u count=2,但增量不起作用。你不认为这应该是testStorage1.Rating\u count吗?`const testObject={Rating\u count:testStorage1,Rating\u date:new date()}59