Twitter Typeahead自定义事件没有触发

Twitter Typeahead custom events aren't firing

本文关键字:事件 Typeahead 自定义 Twitter      更新时间:2023-09-26

我正在制作一个自定义的Angular.js指令来提前包装Twitter类型。键入功能似乎工作得很好,但是似乎没有任何自定义事件被触发。我使用的是Angular 1.2.6, Twitter Typeahead 0.10.2和jQuery 1.10.2。下面是我的几段代码:

search-doctors.html

<div class="controls">
    <div class="span11 input-append">
        <input type="search" class="span10" name="practiceName" ng-model="message.practiceName" required typedown="contactDoctors" />
        <span class="add-on search-glass"><i class="fa fa-search"></i></span>
    </div>
</div>

typedown.coffee

angular.module('someApp')
  .directive('typedown', ->
    restrict: 'A'
    link: (scope, element, attrs) ->
      element.typeahead({
        name: attrs.typedown
        source: (query, cb) ->
          # Ultimately, this will call to a service that will return the array of
          # search results, but for simplicity's sake, I'm stubbing some dummy data.
          cb ['Neurocare of Scottsdale', 'Neurocare of Tempe']
      })
      # These never seem to get fired, despite following the instructions in
      # typeahead's documentation
      .on 'typeahead:opened', ->
        alert 'opened'
      .on 'typeahead:autocompleted typeahead:selected', (event, query) ->
        alert query
)

typedown实际上似乎在UI上工作。当我在搜索框中输入"neuro"时,我得到了预期的行为,但当我按tab键或单击一个选项来自动完成时,相应的事件处理程序没有触发。而且,当我开始键入时,typedown打开,预期的typeahead:opened事件没有触发。

在指令的元素上调用typeahead之前,我已经尝试将事件绑定到元素。我也尝试过使用bind而不是on(虽然这不应该有任何影响)。不管怎样,我的时间和想法都快用完了。我希望能得到一个快速的健康检查和一些额外的眼睛,看看是否有什么我错过了。

提前感谢!

在花了几天时间处理其他事情之后,我回到了自己身边。我突然想到,因为我已经在使用Bootstrap 2.3.2,包括Twitter Typeahead可能会导致与脚本将管理$.fn.typeahead的冲突。我设法通过删除Twitter Typeahead并依赖于内置在Bootstrap 2.3.2中的遗留实现来使其工作。我最终会升级到Bootstrap 3,但现在这个要求有点高,这个项目将在医院中使用,这些医院在网络技术方面是出了名的落后。