How to pass array or a list to Javascript

Nov 18, 2009 at 4: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?



Job Samuel

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

Maybe Indexer is not supported yet.

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



Jan 7, 2010 at 7:31 AM

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

Jan 8, 2010 at 4:59 AM

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



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

                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.



Jan 8, 2010 at 9:02 AM

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


Feb 8, 2010 at 4:48 AM

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