{{x. name}} 如果用户编辑任何单个数据槽,则标记应更新-6ren"> {{x. name}} 如果用户编辑任何单个数据槽,则标记应更新-我正在尝试更改每次用户用英语或印地语编辑标记时的代码,然后相应更新最高的印地语和/或英语标记 Controller 代码 var app = angular.module('myApp', []); -6ren">
gpt4 book ai didi

javascript - {{x. name}} 如果用户编辑任何单个数据槽,则标记应更新

转载 作者:行者123 更新时间:2023-12-03 04:14:31 28 4
gpt4 key购买 nike

我正在尝试更改每次用户用英语或印地语编辑标记时的代码,然后相应更新最高的印地语和/或英语标记

Controller 代码

var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope)
{
$scope.names = [
{name:'Priya',age:'19',gender:'Female',English:x[0], Hindi:x[1]},
....
....
{name:'Dev', age:'18' ,gender:'Male',English:x[2] ,Hindi:x[3]},
];

$scope.sum = function(list)
{
var total=0;
angular.forEach(list , function(x){
total+= x[];
});
return total;
}
});

HTML 代码这是我当前用于显示最高分的代码

<tr ng-repeat ="x in names | orderBy:'sortColumn'">
<td>{{x.name}}</td>
<td>{{x.age}}</td>
<td>{{x.gender}}</td>
<td><input type="text" ng-model="x.English"></td>
<td><input type="text" ng-model="x.Hindi"></td>
<td ng-bind="avg=(x.English+x.Hindi)/2">{{avg}}</td>
<td>
<button><a href="" ng-click="delete(x)">Delete</a></button>
</td>
</tr>
</table>
<table ng-model="sum">
<tr><td>The total is: <input value="{{sum(x)}}"></td></tr>

**<tr><td>THIS IS WHERE I WANT TO DISPLAY HIGHEST MARKS IN ENGLISH</td></tr>**
**<tr><td>**<td ng-repeat="x in names |orderBy:'-Hindi' | limitTo:1"> {{x.name}}THIS IS WHERE I WANT TO DISPLAY HIGHEST MARKS IN HINDI</td></tr>**


</table>

最佳答案

您可以将 watch 放在数组上,如下所示:

$scope.total = 0

$scope.$watch('names', function(newVal) {
var total = 0;
angular.forEach(newVal, function(x) {
total += parseInt(x.English) + parseInt(x.Hindi);
});
$scope.total = total
}, true);

并在模板中将 {{sum(x)}} 替换为 {{total}}

检查工作示例 here

关于javascript - <td ng-repeat ="x in names |orderBy:' -印地语' | limitTo :1"> {{x. name}} 如果用户编辑任何单个数据槽,则标记应更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44199585/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com