I am having a VERY difficult time figuring out how to retrieve data from ACS. I know that callbacks are required (at least I think they are) and I'm having a tough time figuring out how to structure and call the function. I did get table updates to work see my question and answer here. The way this works is that there is a method to set the contents of a table after it is created so even though the execution of the javascript continues once I retrieve the tabledata, I can set it.
Now I want to use ACS more like SQLITE or any regular database. The behaviour I am looking for is below. For example, I have a Photo with the name 'photo.png' stored in ACS. Now I want to query ACS with the photo name (photo.png) then retrieve one of the photo URL's and assign it to a imageView object.
So the code I have is something like this: (simplified example only)
var Cloud = require('ti.cloud'); Cloud.Photos.search({ filename: 'photo.png' }, function (e) { if (e.success) { var photo = e.photos[0].urls.thumb_100; } else { alert('Error:\\n' + ((e.error && e.message) || JSON.stringify(e))); } }); var image = Ti.UI.createImageView({ image:photo });Of course, the above doesn't work because the variable 'photo' is not set by the time we get to creating the imageview.
So, how do you code this thing so that you ensure the variable 'photo' is set before you try and use it in the imageView. I know it has something to do with callbacks but I am having a terrible time understanding this...
Anyone's help would be GREATLY appreciated.
Ray
2 Answers
Maybe something similar to this:
var Cloud = require('ti.cloud'); var image = Ti.UI.createImageView(); Cloud.Photos.search({ filename: 'photo.png' }, function (e) { if (e.success) { image.image = e.photos[0].urls.thumb_100; } else { alert('Error:\\n' + ((e.error && e.message) || JSON.stringify(e))); } });
why dont you just use the image you just uploaded as a place holder until you can query ACS and get it back from the server... Isnt it the exact same image?
Your Answer
Think you can help? Login to answer this question!