How to pass array or a list to Javascript

Nov 18, 2009 at 3:52 PM

If I try to pass a string via the SetParameter call it gets passed correctly and I can access the variable in JS. However when I try to SetParameter an array or a list it gives an exception. For e.g. if I say:

engine.SetParameter("items", arr); where items is an array of Item objects and if I try to access the first element in JS using items[0] it throws an exception. The items variable gets set as if I print items.Length it correctly prints 4.

Can someone please help me fix this or is this scenario not supported yet?

 

Thanks

Job Samuel

Jan 7, 2010 at 6:30 AM
Edited Jan 7, 2010 at 6:35 AM

Maybe Indexer is not supported yet.

for array ,use "GetValue" and "SetValue" method instead.

e.g.

s=items.GetValue(2);

Coordinator
Jan 7, 2010 at 6:31 AM

This is handled right now. Available in the next release, or use the live source code.

Jan 8, 2010 at 3:59 AM

When  testing the latest Version 0.8.8.0,The problem is still the same:

eg:

 

Jint.JintEngine ess = new Jint.JintEngine();          
int[] ss = new int[] { 2, 3, 4, 5, 6, 7 };
List<string> a = new List<string>();
                a.Add("hello1");
                a.Add("hello2");

                ess.SetParameter("ss", ss);
                ess.SetParameter("sp", a);

 object o = ess.Run("return ss[2];");

It throws an exception :


未将对象引用设置到对象的实例。

Line: 1 Char: 0

No source code available.

 

 

Coordinator
Jan 8, 2010 at 8:02 AM

Ok, I see the difference now. I have corrected it and it's available on the live subversion server.

Thanks,
Sebastien

Feb 8, 2010 at 3:48 AM

I have a same problem like you, do you find a way to fix it.