[英]Spreading arrray elements into parameters in 3rd party function javascript
I am building an add in in Microsoft dynamics rms HTML. 我正在Microsoft动态rms HTML中建立一个插件。 need to append parameters into qsbridge function named "ShowMenu".
需要将参数附加到名为“ ShowMenu”的qsbridge函数中。
key = qsBridge.FireEvent("ShowMenu",
"My Menu", // Caption for the menu.
"ParmeterKeyString1", "ParameterValueString1", // Key/value pair for the first option.
"ParmeterKeyString2", "ParameterValueString2", // Key/value pair for the second option.
"ParmeterKeyString3", "ParameterValueString3"); // Key/value pair for the third option.
My array can be unknown in size 我的阵列大小可能未知
var my_array = ["ParamKey1","ParamValue1","ParmKey2","ParmValue2"];
I've tried this. 我已经试过了
qsBridge.FireEvent("ShowMenu","My Menu",my_array);
It gave me an error. 它给了我一个错误。
How can i spread my_array values into function parameters? 我如何将my_array值散布到函数参数中?
You can use the spread syntax : 您可以使用传播语法 :
qsBridge.FireEvent("ShowMenu","My Menu", ....my_array);
Or if that is not supported by the target browsers, you can concat all params to a single array, and use apply : 或者,如果目标浏览器不支持该功能,则可以将所有参数合并为一个数组,然后使用apply :
qsBridge.FireEvent.apply(qsBridge, ["ShowMenu","My Menu"].concat(my_array));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.