[英]how to select value in UI select value?
您能告訴我如何在UI選擇值中選擇值嗎?
實際上,當用戶選擇任何名稱時,我想選擇商品的年齡 。這是我的代碼http://plnkr.co/edit/InxOyQRjrlrDJtx2VuzI?p=preview
<ui-select tagging tagging-label="new tag" multiple ng-model="multipleDemo" theme="select2" ng-disabled="disabled" style="width: 300px;">
<ui-select-match placeholder="Select colors...">{{$item.name}}</ui-select-match>
<ui-select-choices repeat="color in people | filter:$select.search">
{{color.name}}
</ui-select-choices>
</ui-select>
例
當我選擇Amalie MultipleDemo模型值是12或如果我選擇Wladimir是模型值“ 30” ..它是多重選擇的,因此模型應該是數組..
我們能做到嗎?
ui-select
設計方法,它需要ng-model
值作為object
。 在這里你給了一個原始類型
碼
$scope.model = {multipleDemo :[]};
HTML
<ui-select tagging tagging-label="new tag" multiple ng-model="model.multipleDemo" theme="select2" ng-disabled="disabled" style="width: 300px;">
<ui-select-match placeholder="Select colors...">{{$item.name}}</ui-select-match>
<ui-select-choices repeat="color.age as color in people | filter:$select.search">
{{color.name}}
</ui-select-choices>
</ui-select>
<p>Selected: {{test.multipleDemo}}</p>
UI更改只需在ui-select
上添加on-select="OnClickSelect($item)"
和on-remove="OnRemoveSelect($item)"
<ui-select tagging tagging-label="new tag" multiple ng-model="multipleDemo"
on-select="OnClickSelect($item)" on-remove="OnRemoveSelect($item)"
theme="select2" ng-disabled="disabled" style="width: 300px;">
<ui-select-match placeholder="Select colors...">{{$item.name}}</ui-select-match>
<ui-select-choices repeat="color in people | filter:$select.search">
{{color.name}}
</ui-select-choices>
</ui-select>
<p>Selected: {{multipleDemo}}</p>
角度更改在controller
內部添加這些功能
$scope.OnClickSelect=function(item) {
$scope.multipleDemo.push(item.age)
}
$scope.OnRemoveSelect = function(item) {
var index = $scope.multipleDemo.indexOf(item.age);
$scope.multipleDemo.splice(index, 1);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.