gpt4 book ai didi

Angularjs ui-select下拉菜单选择函数调用问题

转载 作者:行者123 更新时间:2023-12-03 06:34:04 24 4
gpt4 key购买 nike

在我的 AngularJS 项目中,我使用正常的选择下拉列表并使用 ng-change 进行函数调用,效果非常好。现在我想将相同的下拉列表迁移到 ui-select。但是 on-select 函数调用不起作用,我尝试了不同的方法但没有运气。请找到我的plnkr

以下是我尝试使用 ui-select 的两种方法:

<ui-select ng-model="uiSelectedCustomer" theme="select2" on-select="getDataBasedonCustomer(uiSelectedCustomer)" style="min-width: 300px;">
<ui-select-match placeholder="Select a customer..">{{$select.selected.name}}</ui-select-match>
<ui-select-choices repeat="cust in customers | filter: $select.search">
<div ng-bind-html="cust.name | highlight: $select.search"></div>
</ui-select-choices>
</ui-select>


<ui-select ng-model="uiSelectedCustomer" theme="select2" on-select="getDataBasedonCustomer(uiSelectedCustomer)" style="min-width: 300px;">
<match placeholder="Select a customer in the list or search his name ">{{$select.selected.name}}</match>
<choices repeat="cust in customers | filter: $select.search">
<div ng-bind-html="cust.name | highlight: $select.search"></div>
</choices>
</ui-select>

最佳答案

我从您的代码中了解到,您希望选择项目并根据选择执行某些操作,如果是这样,请将 on-select="onSelected($item)" 添加到您的 ui-select 和 Controller 中:

$scope.onSelected = function (selectedItem) {
// do selectedItem.PropertyName like selectedItem.Name or selectedItem.Key
// whatever property your list has.
}

关于Angularjs ui-select下拉菜单选择函数调用问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28472529/

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