简体   繁体   中英

Pass multiple args to function

I want to pass multiple values to a function in uploadify.

The way you call a function is like this

$("#id").uploadify("upload", fileId);

here fileId is id of only one file to be uploaded.

I have a scenario where i itertate over a table to get file ids to upload then i want to pass those ids to this function call. How can i do that.

and here is currently what i am doing, which obviously isn't working.

var imagesToUpload = [];
$.each(data.validationResult, function (index, obj) {
var imageToUpload = GetFileToUpload(obj.ImageName);
   if(imageToUpload){
      imagesToUpload[imageToUpload] = imageToUpload;
   }
});
$("#id").uploadify("upload", imagesToUpload);// this is not working

You can use Function.prototype.apply() to pass arguments to a function as an array.

$('#id').uploadify.apply(null, ['upload'].concat(imagesToUpload)); 

This assumes that imagesToUpload is an Array of the arguments you want to pass.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM