2016-10-12 77 views
-1

我的代碼將數字劃分爲dropdownList中的偶數/奇數組。 但是當我在數據部分添加新條目時,dropdownList不會根據它進行調整。DropDownGroups沒有更新在angularJS

角碼:

  angular.module("myModule", []) 
      .controller("myController", function ($scope) { 
       $scope.data = 
          [{ ID: '1', groupID: 'odd', disableID: true }, 
          { ID: '2', groupID: 'even' }, 
          { ID: '3', groupID: 'odd' }, 
          { ID: '4', groupID: 'even', disableID: true }, 
          { ID: '5', groupID: 'odd' }]; 
       $scope.change = function (d) { 
        if (Number(d.ID) % 2 == 0) 
         d.groupID = "even"; 
        else 
         d.groupID = "odd"; 
       } 
      }); 

HTML:

<ul> 
     <li ng-repeat="d in data"> 
      <input type="text" ng-model="d.ID" ng-keyup="change(d)" /> 
      <input type="text" ng-model="d.groupID" readonly="true" disabled="disabled" /> 
      <input type="checkbox" ng-model="d.disableID" /> 
      <input type="button" ng-click="data.splice($index,1)" value="X" /> 
     </li> 
     <li> 
      <input type="button" ng-click="data.push({ disableID : false})" value="add" /> 
     </li> 
    </ul> 
    <select ng-model="drop" ng-options="d.ID group by d.groupID disable when d.disableID for d in data track by d.ID"> 
     <option value="">select value</option> 
    </select> 

什麼我的結果結束了..

enter image description here

回答

0

代替ng-keyup place ng-change

<ul> 
     <li ng-repeat="d in data"> 
      <input type="text" ng-model="d.ID" ng-change="change(d)" /> 
      <input type="text" ng-model="d.groupID" readonly="true" disabled="disabled" /> 
      <input type="checkbox" ng-model="d.disableID" /> 
      <input type="button" ng-click="data.splice($index,1)" value="X" /> 
     </li> 
     <li> 
      <input type="button" ng-click="data.push({ disableID : false})" value="add" /> 
     </li> 
    </ul> 
    <select ng-model="drop" ng-options="d.ID group by d.groupID disable when d.disableID for d in data track by d.ID"> 
     <option value="">select value</option> 
    </select>