[英]switching bw Javascript and GWT function
I am working on a project using GWT and d3. 我正在使用GWT和d3进行项目。 i have used d3 in javascript files.
我在JavaScript文件中使用了d3。 Let me explain a bit more .
让我多解释一下。 i have a class name AstForm in GWT.
我在GWT中有一个类名AstForm。 in this class i have a function which i have called in my javascript file using following code.it the code works fine for me.
在此类中,我有一个函数,已使用以下代码在我的javascript文件中调用了它。该代码对我来说很好用。
public native void PrepareFunctionsForJS() /*-{
$wnd.ExtractOFFNetWork = this.@org.valcri.asstsrchui.client.AstForm::ExtractOFFNetWork(*);
}-*/;
public void ExtractOFFNetWork(JsArrayMixed args)
{
Window.alert("thisCurrent row and Column is " +
args.getString(0) + " " + args.getString(1)+"OffenderNetwork?");
}
void testfunction ()
{
Window.alert("testfunction)
}
in java script i have used the following code 在Java脚本中,我使用了以下代码
window.ExtractOFFNetWork(["GWT","JS"]);
my code works fine. 我的代码工作正常。 i can call the ExtractOFFNetWork in javascript file.
我可以在javascript文件中调用ExtractOFFNetWork。 however the problem is in the ExtractOFFNetWork function when i call testfunction which is also the member function of the ASTFORM class the programe error saying testfunction is not a function.
但是,问题出在我调用testfunction(也是ASTFORM类的成员函数)的ExtractOFFNetWork函数中时,出现程序错误,指出testfunction不是函数。 however when i changed testfunction as static than i can access this function within ExtractOFFNetWork.
但是,当我将testfunction更改为static时,可以在ExtractOFFNetWork中访问此功能。 alternatievly i can also use the testfunction inside ExtractOFFNetWork by creating a separate object of ASTForm as
另外,我还可以通过在ASTForm中创建一个单独的对象来在ExtractOFFNetWork中使用testfunction
AstForm my =new AstForm();
my.testfunction();
however i do not want to use either static or separate ASTform object to access member function of ASTForm. 但是我不想使用静态或单独的ASTform对象来访问ASTForm的成员函数。 i also used this.testfunction() within ExtractOFFNetWork but it also does not work.
我也在ExtractOFFNetWork中使用了this.testfunction(),但它也无法正常工作。 i would appreciate if any body can help to solve my problem i have spend full day without any success :)
如果有人可以帮助解决我的问题,我将花费一整天而没有成功:)
already tried this when calling your PrepareFunctionsForJS
(btw by java naming conventions method names start with lowercase letter..) 在调用
PrepareFunctionsForJS
时已经尝试过此操作(通过Java命名约定,方法名称以小写字母开头。)
//assuming that you are calling the prepare function from inside the AstForm
public class AstForm() {
//...
PrepareFunctionsForJS(this);
}
public native void PrepareFunctionsForJS(AstForm instance) /*-{
$wnd.ExtractOFFNetWork = instance.@org.valcri.asstsrchui.client.AstForm::ExtractOFFNetWork(*);
}-*/;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.