return FALSE; $r = well_tag_thread__update(array('id' => $id), $update); return $r; } function well_tag_thread_find($tagid, $page, $pagesize) { $arr = well_tag_thread__find(array('tagid' => $tagid), array('id' => -1), $page, $pagesize); return $arr; } function well_tag_thread_find_by_tid($tid, $page, $pagesize) { $arr = well_tag_thread__find(array('tid' => $tid), array(), $page, $pagesize); return $arr; } ?>java - How to pass javascript object to GWT method and parse result - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - How to pass javascript object to GWT method and parse result - Stack Overflow

programmeradmin0浏览0评论

I have this GWT method:

public static native JavaScriptObject getJsValue() /*-{
    var res = $wnd.product; 
    return res;
}-*/;

This is the HTML/JS part:

<script type="text/javascript" language="javascript">
    var product = products({id:1}).first(); 
</script> 
<!-- GWT -->
<script type="text/javascript" language="javascript" src="app/app.nocache.js"></script> 

The object product looks like this in Firebug:

Object { id=1, categoryid=0, name="Sample Product", more...}

After then,

Object obj = getJsValue();  // what cast? 

However, how can I parse the resulting value to get the field values like the product id, etc.?

I have this GWT method:

public static native JavaScriptObject getJsValue() /*-{
    var res = $wnd.product; 
    return res;
}-*/;

This is the HTML/JS part:

<script type="text/javascript" language="javascript">
    var product = products({id:1}).first(); 
</script> 
<!-- GWT -->
<script type="text/javascript" language="javascript" src="app/app.nocache.js"></script> 

The object product looks like this in Firebug:

Object { id=1, categoryid=0, name="Sample Product", more...}

After then,

Object obj = getJsValue();  // what cast? 

However, how can I parse the resulting value to get the field values like the product id, etc.?

Share Improve this question asked Mar 19, 2013 at 7:09 quarksquarks 35.4k82 gold badges308 silver badges546 bronze badges 1
  • Please add the answer here,So that will helpful in future. – Suresh Atta Commented Mar 19, 2013 at 8:16
Add a ment  | 

1 Answer 1

Reset to default 6

If I have correctly understood the question, I'd use an overlay type, something like:

public class ProductJso extends JavaScriptObject {
  protected ProductJso() {}
  public final native int getId() /*-{ 
    return this.id;
  }-*/;
  public final native int getCategoryId() /*-{
    return this.categoryid;
  }-*/;
  public final native String getName() /*-{
    return this.name;
  }-*/;
  // And so on...
}

Then modify you JSNI to return the actual JSO type

public static native ProductJso getJsValue() /*-{
  return $wnd.product; 
}-*/;

You get the idea, see also https://developers.google./web-toolkit/doc/latest/DevGuideCodingBasicsOverlay?hl=it#example-json

发布评论

评论列表(0)

  1. 暂无评论