简体   繁体   English

具有本地JS的GWT JSNI方法:“无效标签”

[英]GWT JSNI method with native JS: “Invalid Label”

Maybe my question is simple to solve for you, but I'm sitting here for a few hours with following problem (and I have already searched for it): 也许我的问题很容易为您解决,但是我在这里坐了几个小时,遇到以下问题(并且我已经搜索过):

I have a Java method which has JavaScript code inside (JSNI from Google's GWT) to set key bindings for the code editor CodeMirror2. 我有一个Java方法,其中包含JavaScript代码(Google的GWT中的JSNI)来设置代码编辑器CodeMirror2的键绑定。 When I want to compile with GWT, I'm getting an error from the GWT compiler: 当我想用GWT进行编译时,我从GWT编译器中得到一个错误:

[ERROR] Line 195: invalid label
> "F11": function() {

My code looks like this: 我的代码如下所示:

public final native void setExtraKeysCallback() /*-{
    this.extraKeys = function(editor) {
        "F11": function() {
            // do something
        },
        "Esc": function() {
            // do something
        }
    };
}-*/;

The really strange thing is that in native JS the extra keys are working with this syntax?! 真正奇怪的是,在本机JS中,额外的键正在使用此语法吗? I think the problem is the label syntax, how could I change this to work with GWT? 我认为问题出在标签语法上,如何更改它以使其与GWT一起使用?

Thanks, leX 谢谢,leX

You seem to be mixing object literal syntax: 您似乎在混合对象文字语法:

{ "key": value, "key2", value2 }

… with function expression syntax: …具有函数表达式语法:

function () { }

Decide if you are trying to create a simple object or a function (or a function that returns a simple object) and use the appropriate syntax for that. 确定您是否尝试创建一个简单的对象或一个函数(或返回一个简单对象的函数),并为此使用适当的语法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM