Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/467.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Angularjs在一个字段发生更改时更新其他字段_Javascript_Angularjs - Fatal编程技术网

Javascript Angularjs在一个字段发生更改时更新其他字段

Javascript Angularjs在一个字段发生更改时更新其他字段,javascript,angularjs,Javascript,Angularjs,我重写了这个问题 我的数据是一个对象列表,比如说行。我用这种方式为每一行构建一个类似excel的单元格表 <div ng-repeat="row in dataRows"> <input ng-model="row.a"><input ng-model="row.b">{{row.c}} </div> 我想要实现的是根据a和b的变化自动更新c字段。 我尝试使用$scope.$watch,但这会监视我的整个数据行,我想为更改的行触发一个计算值

我重写了这个问题

我的数据是一个对象列表,比如说行。我用这种方式为每一行构建一个类似excel的单元格表

<div ng-repeat="row in dataRows">
   <input ng-model="row.a"><input ng-model="row.b">{{row.c}}
</div>
我想要实现的是根据a和b的变化自动更新c字段。
我尝试使用$scope.$watch,但这会监视我的整个数据行,我想为更改的行触发一个计算值c

<div ng-repeat="row in dataRows">
  <input ng-model="row.a" ng-change="update($index)"><input ng-model="row.b" ng-change="update($index)">{{row.c}}
</div>

$scope.update = function(index) {
  var row = $scope.dataRows(index);
  row.c = row.a + row.b // or whatever
}

对不起,我什么都不懂。请张贴明确的例子,;预期和实际结果/行为