gpt4 book ai didi

ui-select - 如何从 ui-select multiple 中获取选定的选项

转载 作者:行者123 更新时间:2023-12-02 04:02:21 25 4
gpt4 key购买 nike

我在弄清楚如何从 ui-select 中获取多选表单中的选定值时遇到了一些问题。我制作了一个片段来向您展示我想做的事情。在我的 html 中,我使用 ng-change-event 回调进行了 ui-select:ng-change="onDatasetChanged(whatShouldBehere?)"。选择该选项后,我只想在 Controller 的 onDatasetChanged() 方法内打印所选模型。

angular.module('myApp',['ui.select']).controller('MyController', function ($scope) {

$scope.myUiSelect={model:{}}; // encapsulate your model inside an object.
$scope.availableData=["a","b","c"]; //some random options

$scope.onDatasetChanged = function(selectedValue){
console.log("selectedValue",selectedValue);
}

});
<link href="https://rawgit.com/angular-ui/ui-select/master/dist/select.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://rawgit.com/angular-ui/ui-select/master/dist/select.js"></script>
<body ng-app="myApp" ng-controller="MyController">



<ui-select multiple ng-model="myUiSelect.model" close-on-select="false" title="Choose a dataset" ng-change="onDatasetChanged(whatShouldBehere?)">
<ui-select-match placeholder="Select something">{{$item.label}}</ui-select-match>
<ui-select-choices repeat="data in availableData | filter:$select.search">
{{data}}
</ui-select-choices>
</ui-select>



</body>

最佳答案

ui-select-directive 的存储库页面进行一些研究后我想你可以使用 on-select 事件绑定(bind),如下所示:on-select="onSelect($item, $model)"。查看更新后的代码片段:

angular.module('myApp',['ui.select']).controller('MyController', function ($scope) {

$scope.myUiSelect={model:{}}; // encapsulate your model inside an object.
$scope.availableData=["a","b","c"]; //some random options

$scope.onSelect = function(item,model){
console.log("selectedItem",item);
}

});
<link href="https://rawgit.com/angular-ui/ui-select/master/dist/select.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://rawgit.com/angular-ui/ui-select/master/dist/select.js"></script>
<body ng-app="myApp" ng-controller="MyController">



<ui-select multiple ng-model="myUiSelect.model" close-on-select="false" title="Choose a dataset" on-select="onSelect($item, $model)">
<ui-select-match placeholder="Select something">{{$item.label}}</ui-select-match>
<ui-select-choices repeat="data in availableData | filter:$select.search">
{{data}}
</ui-select-choices>
</ui-select>



</body>

关于ui-select - 如何从 ui-select multiple 中获取选定的选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41279803/

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