如何使用JSNI從GWT創建新的Javascript對象?它沒有在文檔中列出。當我將所有JS移動到.html文件時(但會導致另一個不相關的問題),它將起作用。如何從GWT JSNI創建一個新的Javascript對象?
Java代碼:
private static native void createPicker() /*-{
var picker = new $wnd.google.picker.PickerBuilder()
.enableFeature(google.picker.Feature.NAV_HIDDEN)
....
錯誤:
com.google.gwt.event.shared.UmbrellaException: Exception caught: (ReferenceError) @com.onix.sdm.client.SDM_Mailer::createPicker()([]): google is not defined
從瀏覽器控制檯:
> google
>Object {picker: Object}
參考:
http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJSNI.html
HTML:
<script type="text/javascript">
function loadPicker() {
gapi.load('picker');
}
</script>
<script type="text/javascript" src="https://apis.google.com/js/api.js?onload=loadPicker"></script>