Wednesday, October 2, 2013

Passing Object Literal to Javascript method ?

Please some help on the following.
How to pass an Object literal to a javascript function

I have a javascript function that looks like:
public final native CssHolder perform(Element element, int duration) /*-{
return $wnd.CssMod.perform(element, {opacity: 0.2}); 
}-*/;

This works if I call it from java code.
How can I pass in the Object literal "{opacity: 0.2}" as argument in the above?

So I want something like:
public final native CssHolder  perform(Element element, int duration, Object args) /*-{
return $wnd.CssMod.perform(element, args); 
}-*/;

But what should "args" be ?
I tried to pass in a json data string and eval() it, like 
return $wnd.CssMod.perform(element, eval(args)); 
Or pass in a json string like:
perform(button, 3, "[ \"opacity\" : \"0.2\" ]"
etc...
But it all results in some strange Javascript error :(..
- Ed



--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment