Comments (10)
from react-native-storage.
页面A (是获取数据)
代码:
getSignal = () => {
storage.load({
key: 'signal',
autoSync: true,
syncInBackground: true,
syncParams: {
extraFetchOptions: {
// 各种参数
},
someFlag: true,
},
}).then(ret => {
console.log("信号源列表",ret)
this.setState({
SignalArr: ret
}, () => {
console.log("我state结束了", this.state.SignalArr)
})
}).catch(err => {
});
}
B页面(设置新的数据)
storage.load({
key: 'signal',
autoSync: true,
syncInBackground: true,
syncParams: {
extraFetchOptions: {
// 各种参数
},
someFlag: true,
},
}).then(ret => {
arr =ret
if( this.props.data){ //修改信号源
arr.splice(this.props.index,1,{
name:this.state.name,
type:this.state.type,
channel_num:this.state.channel_num,
id:this.randomId(1,10000000)
})
}else{ //新增信号源
arr.push({
name:this.state.name,
type:this.state.type,
channel_num:this.state.channel_num,
id:this.randomId(1,10000000)
})
}
storage.save({
key: 'signal',
data: arr,
expires: null
}).then( ( ) =>{
// this.props.addSignalModalHide()
storage.load({
key: 'signal',
autoSync: true,
syncInBackground: true,
syncParams: {
extraFetchOptions: {
// 各种参数
},
someFlag: true,
},
}).then(ret => {
console.log("设置信号源后的",ret)
})
Actions.A() //跳到 A页面
})
}).catch(err => {
arr.push({
name:this.state.name,
type:this.state.type,
channel_num:this.state.channel_num,
id:this.randomId(1,10000000)
})
storage.save({
key: 'signal',
data: arr,
expires: null
}).then( ( ) =>{
console.log("我设置了err")
this.props.addSignalModalHide()
})
});
from react-native-storage.
你这个嵌套太难读了,建议改成async/await再看看
from react-native-storage.
这是简化后的,在更新的页面可以获取到新的值,但是在前面已经获取过一次的,返回再次获取到的就不是新的值,还是老的值
A页面
storage.load({
key: 'title',
autoSync: true,
syncInBackground: true,
syncParams: {
extraFetchOptions: {
// 各种参数
},
someFlag: true,
},
}).then(ret => {
console.log("a页面获取的到的:",ret)
this.setState({
title: ret
})
}).catch(err => {
});
B页面:
titleChange = (text)=>{
storage.save({
key: 'title',
data: text,
expires: null
})
this.setState({
title:text
})
storage.load({
key: 'title',
autoSync: true,
syncInBackground: true,
syncParams: {
extraFetchOptions: {
// 各种参数
},
someFlag: true,
},
}).then( (ret)=>{
console.log( "B页面设置后的",ret)
} ).catch( err =>{
})
}
from react-native-storage.
from react-native-storage.
- 建议用
async/await
语法 - 有没有可能new了多个storage的实例?
- 如果是B页面输入然后跳回A页面取值,那么没必要用storage传递,直接用回调更合适,更简单,性能也更好
from react-native-storage.
没有办法啊,数据只能存再本地,局域网软件的
from react-native-storage.
看你B页面的代码,不是textinput输入取值吗?这个跟本地局域网的有啥关系?
from react-native-storage.
需要textinput输入的值保留下来,下次打开app,直接读取这条数据
from react-native-storage.
谢谢你,想到解决方法了,可以在a页面设置就行了,不一定要在b页面设置
from react-native-storage.
Related Issues (20)
- syncInBackground: false seems to not work and always leave data undefined HOT 4
- Request - Publish 1.0.1 HOT 2
- 如何同步获取数据? HOT 4
- RN warning when calling getAllDataForKey with many keys
- @react-native-community/async-storage could not be found within the project. HOT 3
- Will I lost data on expire time change? HOT 2
- Please do not use "_" in key!"data" is required in save()!
- "data" is required in save() HOT 3
- 怎么才能取出异步存的值,然后把它给header呢 HOT 18
- ERROR: The modules ['@react-native-community_async-storage', 'react-native-community_async-storage'] point to the same directory in the file system. Each module must have a unique path. HOT 2
- How can I get list of all keys?
- Bundle size doubled in 1.0.1? HOT 1
- database or disk is full HOT 1
- Vulnerabilities during npm install
- Update peer dependencies
- Unhandled JS Exception: [@RNC/AsyncStorage]: NativeModule: AsyncStorage is null. HOT 1
- How to Ignore expiry HOT 6
- I have a issue when i run on iPhone HOT 2
- 有时获取不到刚存的数据 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-storage.