Closed zacksleo closed 6 years ago
LLS has to be async since the FilesystemAPI, IndexedDB and WebSQL (the implementations behind large local storage) are all a-sync. You would get the return value much like you would get the value from an event handler in jQuery.
storage.getContents(name, {json: true}).then(function(contents){
// You have the return value of getContents here in the `contents` variable
})
For your situation, you should be able to just move the code that needs the return value into the callback that is receiving the return value.
Right now you have:
storage.getContents(name, {json: true}).then(function(contents){ // first then
value = contents;
}).then(function(contents) { // second then
...more code...
})
You can remove the first then
enitrely or return a value from the first then
so it can be passed to the second then
Right now nothing is passed to the second then
since nothing is returned from the first then
.
Also, your statement value = content
has a typo. If you are going to keep it it should be value = contents
although I don't see why you need the firstthen
at all.
hi @tantaman:
Question
I'm confused when using the LLS in my code. I don't know how go get the return value in the function getData because it's async which is beyond my expect. In the console, the function getData always return null (Line 65), "4:end" is print before others ("like 3.1 or 3.2")
Could you tell me what should I do ?
Code