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