2015-04-17 50 views
1

我使用以下命令根據服務器數據創建多個ui-select下拉列表。我喜歡從每個下拉菜單中選擇獨立的項目。當我在一個下拉列表中選擇一個項目時,所有下拉列表都會分配相同的值。我怎樣才能分離選定的值?使用單獨的選定值進行多個ui選擇

  <div ng-repeat="choiceItem in menuItem.mandatoryChoices"> 
      <ng-form name="innerModalForm1"> 
       <div class="form-group"> 
        <label ng-show="choiceDescExist(choiceItem)">{{choiceItem.choiceDesc}}</label> 

        <div ng-class="{ 'has-error' : innerModalForm1.option.$invalid && submitted }"> 
         <div ng-show="choiceItem.multiSelect"> 
          <ui-select name="mandatory" multiple required ng-model="selected.mandatoryChoices[$index]"> 
           <ui-select-match placeholder="Please select one or more"> 
            {{$select.selected.choiceItemDesc}} 
           </ui-select-match> 
           <ui-select-choices repeat="s in choiceItem.choiceOptions | filter: $select.search"> 
            <div ng-bind-html="s.choiceItemDesc | highlight: $select.search"></div> 
           </ui-select-choices> 
          </ui-select> 
         </div> 
        </div> 
        <span class="has-error" ng-show="submitted && innerModalForm1.option.$invalid">You must select this required item</span> 
       </div> 
      </ng-form> 
     </div> 

這裏是截圖。所有三個下拉菜單都有不同的值。

enter image description here

+0

[Rü尋找這個/ edit/95wvJb?p = preview – Reena

+1

開始這樣做:''。如果有效,讓我們繼續前進。 –

+0

@Werlang,它沒有工作。隨着你所提出的改變,我是否也需要改變'{{$ select.selected.choiceItemDesc}}'中的內容? – Nabarun

回答

3

兩件事情:

  • multiple屬性:它的目的是當一個選擇可以有多個選擇的值
  • ngModelng-repeat/$index:雖然它可以工作,也許它是更新錯誤的型號

因此,更好的辦法是做:

<ui-select name="mandatory" required ng-model="choiceItem.selected"> 

而且,當有一個ng-model複雜的表情,我喜歡我的輸出模式,JSON:http://plnkr.co

{{ctrl.models | json}} 
相關問題