我想在GWT中使用javascript库。
我将文件放在公共文件夹中,以便在客户端和服务器之间共享,并按照本教程(https://pelle.io/2015/01/27/integrating-javascript-libraries-into-gwt-using-jsni/)注入javscript。
StyleInjector.inject(INSTANCE.fullcalendarCSS().getText());
StyleInjector.inject(INSTANCE.fullcalendarPrintCSS().getText());
StyleInjector.inject(INSTANCE.schedulerCSS().getText());
ScriptInjector.fromString(INSTANCE.jqueryJS().getText()).setWindow(ScriptInjector.TOP_WINDOW).inject();
ScriptInjector.fromString(INSTANCE.momentJS().getText()).setWindow(ScriptInjector.TOP_WINDOW).inject();
ScriptInjector.fromString(INSTANCE.fullcalendarJS().getText()).setWindow(ScriptInjector.TOP_WINDOW).inject();
ScriptInjector.fromString(INSTANCE.scheduleJS().getText()).setWindow(ScriptInjector.TOP_WINDOW).inject();
每次执行我的javscriptcode时,我都会遇到“非函数”异常。
public static native void drawScheduler() /*-{
var calendar = $doc.getElementById("calendar");
calendar.fullCalendar({
defaultView: 'timelineMonth',
events: [
// events go here
],
resources: [
// resources go here
]
// other options go here...
});
}-*/;
答案 0 :(得分:2)
假设fullCalendar
来自jQuery插件,那么DOM元素不会被修改;你需要把它包装在jQuery"对象" (通常为$(calendar)
,此处可能为$win.$(calendar)
)