简体   繁体   English

数组作为函数参数

[英]array as function param

I have flash application, which creates array and calls javascript function. 我有Flash应用程序,该应用程序创建数组并调用javascript函数。

var jsParams = ["3011","3012","3013","3014","3015"];
ExternalInterface.call("doCall", jsParams);

And this is my javascript function: 这是我的javascript函数:

function doCall(params) {
  console.log(params);
  console.log(params[0]);
}

The output in the firebug is: 萤火虫的输出为:

["3011","3012","3013","3014","3015"]
[

But for the second line i was expecting 3011 and not [. 但是对于第二行,我期望3011而不是[。 Then i have tried to call same function with same params from firebug and the function outputed: 然后我试图从萤火虫中调用具有相同参数的相同函数,并输出以下函数:

doCall(["3011","3012","3013","3014","3015"]);
["3011","3012","3013","3014","3015"]
3011

My question is how to pass params from actionscript to javascript as array and not as string value. 我的问题是如何将参数从动作脚本传递给javascript,而不是作为字符串值。

Thanks. 谢谢。

It looks like the params variable is being passed in as a string, rather than an array. 看起来params变量是作为字符串而不是数组传递的。

Square bracket notation, when applied to a string, represents the character at the supplied index, which in this case would be the '[' (position 0). 如果将方括号符号应用于字符串,则表示所提供索引处的字符,在这种情况下,该字符将为“ [”(位置0)。

You should look into JSON decoding to find a safe way to convert the string back into an array , I wouldn't recommend eval , and JSON.decode isn't widely supported. 您应该研究JSON解码,以找到将字符串转换回数组的安全方法,我不建议eval ,并且不广泛支持JSON.decode

have you tried encapsulating the array within another array? 您是否尝试过将数组封装在另一个数组中?

ExternalInterface.call("doCall", [jsParams]); ExternalInterface.call(“ doCall”,[jsParams]);

I think a initial array is so you can pass mulitple sets of parameters 我认为初始数组是这样,您可以传递多个参数集

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

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