在结束一些javascript代码时,我遇到了一个JsInterop问题。
JavaScript就像
com = { gwidgets: {} };
com.gwidgets.Spring = function () {
this.name = "hello";
};
com.gwidgets.Spring.prototype.getName = function () {return "test";
};JsInterop类是:
package com.gwidgets.leaflet;
import jsinterop.annotations.JsMethod;
import jsinterop.annotations.JsType;
@JsType(isNative=true)
public class Spring {
@JsMethod
public native String getName();
}但是,当我实例化类并尝试调用getName()方法时,会得到一个错误:
树叶-0.js:1183隐TypeError: spring.getName不是函数
有什么想法吗?我的代码有什么问题?
发布于 2016-05-27 17:58:43
根据您拥有的javascript,一种解决方案可以是在注释中添加命名空间。
import jsinterop.annotations.JsMethod;
import jsinterop.annotations.JsType;
@JsType(isNative=true, namespace = "com.gwidgets")
public class Spring {
@JsMethod
public native String getName();
}或者将java类Spring移动到包com.gwidgets (与javascript相同)
或更改javascript的命名空间以匹配类Spring中的包
https://stackoverflow.com/questions/37472310
复制相似问题