1

I am using the file.saveURL in a loop and its working good but I am seeing some strage things. Basically I loop over about 70 images and then grab the uri to them after they are saved and store that locally so I can then use it to display in the app

What happens is that once the loop is done I display the images out but randomly some of the images are the same. I have validated the correct URL is being passed but its as if and I don't know for sure but maybe the function is not done with the previous and is somehow overwriting it?

This makes the most sence because the issue usually happens with images right next to each other.

So I guess my question is, does the file.saveURL only work on a one to one aspect, like it has to by synchronous?

If that is the case what would be the recommended approach for looping over and saving these images.

Thanks!

EDIT

This is a basic sample (I have some conditional stuff in there but this is the main part)

I have the JSON object stored and I loop over it

$(data).each(function(i){

        var slcval = 'speaker' + this.SID;
        var imageID = 'simageid' + this.IMAGE;
        var  speakerImage = "http://mydomain.com/users/images/speakers/" + this.IMAGE;

//then I call the save url function 
        saveURLImage(speakerImage,slcval,'speaker',this.SID,imageID);
}

this loops over my images and calls the save image function that then does the save URL function

function saveURLImage(url,ID,type,extraVal,imageID){
forge.file.saveURL(url, function (file) {
       forge.file.URL(file, function (url) {
        var fileObject = JSON.stringify(url);

        localStorage.setItem(ID, fileObject);


        })
        });
 }

This is a simple version of it, I have some other parts that set some localstorage vars but this is the main call.

4

1 回答 1

1

所以我的问题是范围问题

所以如果其他人来arrocss这个我发现这个帮助了

Javascript:setTimeout 中的函数和引用

基本上我所做的是创建一个函数,其中包含一个匿名函数,因此范围是正确的

函数 saveURLImage(url,ID,type,extraVal,imageID) { (function() { saveURLImageScoped(url,ID,type,extraVal,imageID) })(); }

所以函数名称仍然和以前一样,但我重命名了主函数 saveURLImageScoped,现在它有自己的变量范围

于 2013-04-04T21:45:29.420 回答