2

你能告诉我如何在UI选择值中选择值吗?如何在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> 

当我选择利亚multipleDemo模型值 或者我选择Wladimir是型号值“30”.. 它是多重选择所以型号应该是阵列..

我们可以做到这一点吗?

回答

0

UI变化只需添加on-select="OnClickSelect($item)"on-remove="OnRemoveSelect($item)"ui-select

 <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);  
} 

plnkr

+0

它不是当前我需要多个选择 – user944513

+0

它应该给'年龄'的数组。非单一时代 – user944513

+0

@ user944513请检查更新 – Moumit

2

方式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> 

Plunkr

+0

这些功能,请分享plunker – user944513

+0

是选择全object..http://plnkr.co/edit/InxOyQRjrlrDJtx2VuzI?p =预览。我只需要对象 – user944513

+0

中的“age”,它不会选择年龄数组。它是对象数组 – user944513