Ich bin neu in AngularJS ich json Daten immer bin, die in Format ist:Tabellenzeile Farbe nach führen
[
{
'StudentName':'abc',
'maths':'0',
'english':'0',
'economics':'0',
}
]
Ich mag jeden Student Noten berechnen und wenn Mark weniger als 40%, dann Zeile Tabelle sollte sei rot, sonst sollte es grün sein. Ich habe es versucht. HTML
<div ng-app="MyApp" ng-controller="con1">
<table id="table1">
<tr>
<th>student Name</th>
<th>History Marks</th>
<th>Maths Marks</th>
<th>Economics Marks</th>
<th>Percentage</th>
</tr>
<tr ng-repeat="x in data" ng-if="{{co(per(x))}}" ng-class="pass">
<td>{{x.StudentName}}</td>
<td>{{x.maths}}</td>
<td>{{x.economics}}</td>
<td>{{x.english}}</td>
<td>{{per(x)}}%</td>
</tr>
</table>
Script
var app = angular.module('MyApp', []);
app.controller('con1', function ($scope, $http) {
$http.get('/ajax/data').success(function (res) { $scope.data = res; });
$scope.per = function (x) {
avg = ((parseInt(x.maths) + parseInt(x.economics) + parseInt(x.english)) * 100)/300;
return avg;
};
$scope.co = function (x) { (x > 40) ? k = 1 : k = 0; return (k); }
});
css
.pass{background:green;}
.fail{background:red;}
ich Prozentsatz bin immer aber nach Prozentsatz ich nicht die Zeilenfarbe bin immer.
wenn neu zu angularjs ist es sehr gut, keine ANY jQuery zu verwenden – DrCord
Ich sehe tatsächlich nicht, wo jQuery verwendet wird. – Nick
Ich denke, viele Leute verwechseln jQuery mit Javascript. – Scottie