需要将参数转换为数组

Need to convert parameter into array

本文关键字:数组 转换 参数      更新时间:2023-09-26

我有下面的代码:

.attr("onclick", "Display('"Do you wish to do this?'",null," + Test.toggle + ",'"" + [Test.Comment,Test.Valid == "True"] + "'");")

这很好,它调用了一个叫做Test.toggle(Test.Comment,Test.Valid);

的函数

问题是,在Test.toggle()我使用的是.apply()函数,它期望一个数组而不是参数(.call())。我不能改变函数Test.toggle(),所以它开始使用.call(),所以我必须提供一个对象数组来代替。

。函数调用必须看起来像Test.toggle([Test.Comment,Test.Valid]);

我该怎么做?

我尝试了

.attr("onclick", "AlertBox('"Do you wish to do this valid thing?'",null," + EpgTest.toggleValid + ",'"[" + [data.Id + "," + data.Valid == "True"] + "]'");")

这是在外面添加额外的"["标志,但它不起作用。你们能帮帮我吗?

一种选择是使用Test.toggle的包装器函数,该函数接受非数组参数并将它们传递给toggle,如下所示:

Test.wrappedToggle = function(a,b){ return Test.toggle([a,b]); };

你可以使用wrappedToggle来代替toggle