gpt4 book ai didi

javascript - AngularStrap typeahead,如何使用事件回调

转载 作者:行者123 更新时间:2023-12-02 14:23:01 24 4
gpt4 key购买 nike

我正在使用 AngularStrap typeahead,并且当用户选择某个项目时需要回调。根据documentation ,有一个 onSelect 选项,可以通过 function 提供,并且:

If provided, this function will be invoked when an item is selected.

…和…

Options can be passed via data-attributes on the directive or as an object hash to configure the service. For data attributes, append the option name to data-, as in data-animation="".

所以我尝试按如下方式使用它:

<input type="text" 
class="form-control"
ng-model="selection"
bs-options="item for item in items"
bs-typeahead
data-on-select="onSelect">

并在我的 Controller 中提供onSelect() 方法:

$scope.onSelect = function() {
console.log('this never gets called :(');
};

但是,回调函数永远不会被调用。我这里缺少什么吗?

<小时/>

[编辑] dfsq 指出,关于库的来源,它应该是 bs-on-select。我刚刚尝试了这个变体,但是该事件只触发一次。我创建了this Plunker说明我的问题; “选择事件的数量”自然应该随着每次选择而增加,但它仍然是 1。

最佳答案

看起来 @Vanojx1 在评论中回答了这个问题它应该是:

bs-on-select="onSelect"

我已经更新了 Plunker进行此更改后,它就可以工作(但是,直到输入失去焦点为止,它不会调用该方法)。

关于javascript - AngularStrap typeahead,如何使用事件回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38523871/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com