【问题标题】:External function call from JSNI is not working来自 JSNI 的外部函数调用不起作用
【发布时间】:2015-06-29 15:39:25
【问题描述】:

我正在尝试将此 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

什么可能导致这个错误?

【问题讨论】:

  • 欢迎来到 Stack Overflow!我已经编辑了您的问题,以使代码更具可读性,并希望能得到更多人的帮助。祝你好运!

标签: javascript java jquery gwt jsni


【解决方案1】:

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

【讨论】:

  • 感谢 Tom,只需将 $wnd 添加到现有代码中即可完美运行此语法。 $wnd.$('#q').typeahead({ 。我在“SmartGWT”上使用了完全相同的语法。就此而言,什么都没有显示。 $wnd.$('#q').length 本身为 0。对象未被识别。有什么想法为什么?
  • 智能gwt实现jquery和外部js的解决方案定义在下面的链接[smartclient.com/smartgwt/javadoc/com/smartgwt/client/docs/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-22
  • 1970-01-01
  • 2010-12-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多