On Jul 17, 10:21 pm, byhisdeeds <[email protected]> wrote:
> I have a GWT application with a JSONObject which must be passed to a
> javascript function which will make some calculations, which will then
> be returned to the calling GWT app.
>
> ie:
>
> JSONObject json = new JSONObject();
> json.put("x", 2);
> json.put("y", 5);
> JSONObject result = process(json)
> Window.alert("sum="+result.get("sum"));
> Window.alert("average="+result.get("avg"));
>
> public native JSONObject process(json) /*-{
> return $wnd.myJavascriptFunction(json);
> }-*/;
>
> My question is what is the correct way to reference the JSON object
> within my javascript function, and when it must return my results in
> another JSON obejct how do I do this in javascript.
JSONObject wraps a real JavaScriptObject, so using:
JavaScriptObject unwrapped = json.getJavaScriptObject();
JavaScriptObject result = process(unwrapped);
json = new JSONObject(result);
public native JavaScriptObject process(JavaScriptObject o) /*-{
return $wnd.myJavascriptFunction(o);
}-*/;
should do what you want.
$wnd.myJavascriptFunction will get and return a normal
javascript object.
Gert
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---