简体   繁体   中英

How to select the elements in the array?

Using Awesomium .net for windows forms.

My code-behinde to call a java script functions passing arguments(JSValue).

JSValue[] args = new JSValue[args2.Length];

for (int i = 0; i < args2.Length; i++)
{
args[i] = args2[i].ToString();
}

JSObject js_obj = webControl1.ExecuteJavascriptWithResult("window");
//args has all my 35 elements.
js_obj.Invoke("addTheseElements", args);

REFERENCE http://docs.awesomium.net/html/M_Awesomium_Core_JSObject_Invoke.htm http://answers.awesomium.com/questions/784/calling-a-javascript-method-with-parameters.html

My HTML page

<script>

function addTheseElements(args) {

alert(args);
//returns element1

alert(args[0]);
//returns e

alert (args.length) 
//returns 8 (element1)

}

</script>

Problem is that I'm not able to select the 2nd element in the array. How do i access it? What am i doing wrong?

JSValue的结构。可用的属性和方法

OK I'm not sure if this is the right way to do it but turns out that the second parameter I need to pass is JSValue object and not an JSValue[].

So my working answer was

        JSValue[] args = new JSValue[args2.Length];

        for (int i = 0; i < args2.Length; i++)
        {
            args[i] = args2[i].ToString();

        }

        JSValue args3 = args;

        JSObject js_obj = webControl1.ExecuteJavascriptWithResult("window");

        js_obj.Invoke("addTheseElements", args3);

But the syntax given in the documentation was

public JSValue Invoke(
    string methodName,
    params JSValue[] args
)

REF http://docs.awesomium.net/html/M_Awesomium_Core_JSObject_Invoke.htm

Please feel free to explain if anybody finds out what happened here.

Cheers.

Try to change this one:

args[i] = args2[i].ToString();

To:

args[i].push_back(args2[i].ToString());

before passing.

So that it would become:

JSValue[] args = new JSValue[args2.Length];

for (int i = 0; i < args2.Length; i++)
{
 args[i].push_back(args2[i].ToString());
}

JSObject js_obj = webControl1.ExecuteJavascriptWithResult("window");

js_obj.Invoke("addTheseElements", args);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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