简体   繁体   English

将多个参数传递给函数

[英]Pass multiple args to function

I want to pass multiple values to a function in uploadify. 我想将多个值传递给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. 这里的fileId是仅一个要上传文件的ID。

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. 我有一个场景,我遍历一个表以获取要上传的文件ID,然后将这些ID传递给此函数调用。 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. 您可以使用Function.prototype.apply()将参数作为数组传递给函数。

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

This assumes that imagesToUpload is an Array of the arguments you want to pass. 假定imagesToUpload是要传递的参数的数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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