通过JSNI将GWT的值传递给Javascript [英] Pass value from GWT to Javascript via JSNI

查看:107
本文介绍了通过JSNI将GWT的值传递给Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这个方法是否有效:

$ b是一个有效的方法
$ b

  public static native JavaScriptObject getProductById(long pid)/ *  -  {
var productId = pid;
var product = $ wnd.products({id:productId})。first();
退货产品;
} - * /;

我可以说JS方法是正确的,因为如果我将一个常量值放在 productId ,我得到正确的输出。



我缺少什么?

解决方案

JSNI不允许使用 long 作为输入变量,请参阅 here。



你可以尝试使用double(或者甚至是int)来代替,但是要确保你的Javascript代码支持它。

  public static native JavaScriptObject getProductById(double pid)/ *  -  {
var productId = pid;
var product = $ wnd.products({id:productId})。first();
退货产品;
} - * /;


I've been trying to pass a value into a Javascript method through JSNI but it keeps on failing.

Is this method valid:

public static native JavaScriptObject getProductById(long pid) /*-{
    var productId = pid;
    var product = $wnd.products({id:productId}).first();    
    return product;
}-*/;

I can say that the JS method is correct, since if I put a constant value in place of productId, I get the correct output.

What am I missing?

解决方案

JSNI does not allow using long as input variable, see explanation here.

You could try using double (or even int) instead, but make sure that your Javascript code supports it.

public static native JavaScriptObject getProductById(double pid) /*-{
    var productId = pid;
    var product = $wnd.products({id:productId}).first();    
    return product;
}-*/;

这篇关于通过JSNI将GWT的值传递给Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆