简体   繁体   English

如何在Javascript中读取从C#传递的params object []项目?

[英]How to read params object[] items passed from C# in Javascript?

I am doing a simple program in Silverlight to inkove javascript function in silverlight. 我正在Silverlight中做一个简单的程序来在Silverlight中使用javascript函数。

The silverlight function is as under Silverlight功能如下

void InvokeJS(params object[] items)
{
object result = System.Windows.Browser.HtmlPage.Window.Invoke("JSFunction", items);
}

Pasing value to this function is happening as under 正在向此功能付款

  InvokeJS((object)new object[]{ (object)"10", (object)"20"})

And the JS function is as under 和JS功能如下

function JSFunction(params) {
            alert(params);
        }

Now how to read the params value in javascript? 现在如何读取javascript中的params值?

To the called function, the params array is just that, an array. 对于被调用的函数,params数组就是那个数组。

In this case you will have an array that looks like this: 在这种情况下,您将拥有一个如下所示的数组:

[ [ "10", "20" ] ]

The params variable is just the first of many arguments being passed in. You can access the other arguments using the following syntax: params变量只是传入的许多参数中的第一个。您可以使用以下语法访问其他参数:

alert(this.arguments[0]);
alert(this.arguments[1]);
alert(this.arguments[2]);

If you're passing all the arguments in a single variable, it will be an array so use: 如果要在单个变量中传递所有参数,则它将是一个数组,请使用:

alert(params[0]);
alert(params[1]);
alert(params[2]);

我知道了

alert(params[0]); alert(params[1]);

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

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