Javascript Angularjs在一个字段发生更改时更新其他字段
我重写了这个问题 我的数据是一个对象列表,比如说行。我用这种方式为每一行构建一个类似excel的单元格表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,但这会监视我的整个数据行,我想为更改的行触发一个计算值
<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
}
对不起,我什么都不懂。请张贴明确的例子,;预期和实际结果/行为