来自JSNI的外部函数调用无效

时间:2015-06-29 15:39:25

标签: javascript java jquery gwt jsni

我正在尝试将此JavaScript代码翻译为JSNI代码。

脚本导入

<script src="jquery-1.11.2.min.js"></script>
<script src="jquery.typeahead.min.js"></script>
<script src="autocompletetest/autocompletetest.nocache.js"></script>

脚本

$('#q').typeahead({  
    minLength: 1,  
    order: "asc",  
    group: true,   
    groupMaxItem: 6,  
    hint: true,  
    dropdownFilter: "All",  
    href: "https://en.wikipedia.org/?title={{display}}",  
    template: "{{display}}, <small><em>{{group}}</em></small>",  
    source: {  
        country: {  
            data: data.countries  
        },  
        capital: {  
            data: data.capitals  
        }  
    },
    ...

$doc.getElementsByClassName("q").typeahead({
    ...
})

但是我收到了这个错误:

@com.citi.sevi.client.AutocompleteTest::loadJquery()([]): $doc.getElementsByClassName(...).typeahead is not a function

可能导致此错误的原因是什么?

1 个答案:

答案 0 :(得分:1)

jQuery的$函数不仅仅是getElementsByClassName包装器,它将结果包装在插件所在的jQuery对象中。要调用typeahead方法,您 要使用$win.$("q")

相关问题