5
我导出GWT方法本地JavaScript以下列方式:找出当GWT模块加载
public class FaceBookGalleryEntryPoint implements EntryPoint {
@Override
public void onModuleLoad() {
FacebookGallery facebookGallery = new FacebookGallery();
RootPanel.get().add(facebookGallery);
initLoadGallery(facebookGallery);
}
private native void initLoadGallery(FacebookGallery pl) /*-{
$wnd.loadGallery = function (galleryId) {
[email protected]::loadGallery(Ljava/lang/String;)(galleryId);
};
}-*/;
}
在主机页面,我想调用它:
<html>
<head>
<title>Facebook image gallery</title>
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript" src="/fbg/fbg.nocache.js"></script>
<h1>Facebook gallery test</h1>
<script type="text/javascript">
$(document).ready(function() {
loadGallery('blargh');
});
</script>
</body>
</html>
不幸的是,当调用document.ready回调函数时,该函数尚未定义。当从Firebug控制台手动执行时,该功能工作得很好。
我可以每隔50毫秒执行一次轮询,直到找到一个由该名称定义的函数,但它看起来像一个可怕的方法。
如何在模块加载时得到通知,因此当功能可用时?
谢谢,看起来有趣 - 尤其是DeferredCommand位。今晚我会说这个。 – 2010-11-18 07:31:39
顺便说一句,与GWT 2.1你应该使用调度程序()。get()。scheduleDeferred() – 2010-11-18 19:38:39
感谢您的调度程序提示。 – vanje 2010-11-18 20:14:56