DropdownGroups未在angularJS中更新

时间:2016-10-12 10:32:06

标签: html angularjs

我的代码在dropdownList中将偶数/奇数组中的数字分开。 但是当我在数据部分添加新条目时,dropdownList不会根据它进行调整。

角度代码:

         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

1 个答案:

答案 0 :(得分:0)

取代ng-keyup place ng-change

onQueryTextChange