简体   繁体   English

GWT + SmartGWT + Javascript:外部脚本集成

[英]GWT + SmartGWT + Javascript: external script integration

I am building a web application using GWT and SMartGWT and I need to integrate an external script for a Photo Gallery: http://slideshow.triptracker.net/ . 我正在使用GWT和SMartGWT构建Web应用程序,并且需要为照片库集成外部脚本: http ://slideshow.triptracker.net/。 My current attempt is: 我目前的尝试是:

ScriptInjector.fromUrl("http://slideshow.triptracker.net/slide.js").setCallback(
              new Callback<Void, Exception>() {
                     public void onFailure(Exception reason) {
                       Window.alert("Script load failed.");
                     }
                    public void onSuccess(Void result) {
                      Window.alert("Script load success.");
                     }
                  }).inject();

Afterwards, I call this method: 之后,我调用此方法:

Code: 码:

native static void example(String p) /*-{

     $wnd.viewer = new $wnd.PhotoViewer();
             $wnd.viewer.add(p)
     $wnd.viewer.show(0);

}-*/;

This does not give any error, but the photogallery appears BEHIND my Entry Point Layout, so it's not possible to use it. 这不会给任何错误,但出现照相馆背着我进入点布局,因此它不可能使用它。

So, I am trying to find a workaround and I would like to refer to the main layout from Javasript, to run the script on that. 因此,我试图找到一种解决方法,我想参考Javasript的主要布局,以便在该脚本上运行脚本。 Is this possible? 这可能吗? I've tried with 我尝试过

 foo.getElement().getId();

but it returns me something like 但是它给我类似的东西

 isc_VLayout_0_wrapper

However, Javascript doesn't like it. 但是,Javascript不喜欢它。

Then I tried 然后我尝试

  foo.getDOM.getId();

  isc_1

But the result doesn't change. 但是结果没有改变。

Can someone help me fix this issue? 有人可以帮我解决此问题吗? Thank You. 谢谢。

I think here are two things, that are possibly wrong: 我认为这是两件事,可能是错误的:

  1. You have an onSuccess() callback you can call the jsni call from within. 您有一个onSuccess()回调,您可以从内部调用jsni调用。

     //1 ScriptInjector.fromUrl("http://slideshow.triptracker.net/slide.js").setCallback( new Callback<Void, Exception>() { public void onFailure(Exception reason) { //3a } public void onSuccess(Void result) { example("works"); //3b } }).inject(); //2 example("not loaded"); 
  2. You may also try to call .setWindow(ScriptInjector.TOP_WINDOW) before calling .inject() 您还可以尝试在调用.setWindow(ScriptInjector.TOP_WINDOW)之前调用.inject() .setWindow(ScriptInjector.TOP_WINDOW) .inject()

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

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