观看多个字段不能与$ watchGroup一起使用

时间:2018-09-10 21:27:59

标签: javascript .net angularjs angularjs-scope

我想根据页面上两个字段的组合自动填充日期字段。主页是“机构”,在该主页中,有一个子部分供员工使用。我想看小节中的2个字段,我尝试了这段代码,但是没有用。

  $scope.$watch(function () { return vm.institution.employees.length }, function () {
    _.forEach(vm.institution.employees, function (item, index) {
        $scope.$watchGroup(['vm.institution.employees[index].occupation','vm.institution.employees[index].salary'], function (newValue, oldValue) {
            if (newValue[0] != oldValue[0]) {
                vm.xx = 'test';
            }
        },true);

    });
});

在同一机构页面的“雇员”子部分中,我正在使用以下代码监视单个属性,该属性正常工作,但是在监视2不起作用。

$scope.$watch(function () { return vm.institution.employees.length }, function () {
    _.forEach(vm.institution.employees, function (item, index) {
        debugger;
        item.employeeDesignation = _.filter(vm.desginations, { id: item.designationTypeId });
        $scope.$watch(function () { return vm.institution.employees[index].designationTypeId }, function (newValue, oldValue) {
            if (newValue != oldValue) {
                item.employeeDesignation = _.filter(vm.desginations, { id: newvalue });
                       }
        });

    });
});

0 个答案:

没有答案