ng-repeat its repeat names when there is more than one subjects
html code
this problam is dublecate the name if there are more then one grade for subjects in the same month i need to delete the dublcate name
i wantto show only name and the marks with aout rpeat names
please help me to solve this proplame.
<code><table class="table table-bordered table-hover" style="font-size:18px">
<thead>
<tr style="font-size: 20px; font-weight: bold">
<th>Name</th>
<th ng-repeat="subject in subjects">{{ subject }}</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="student in students">
<td>{{ student.name }}</td>
<td ng-repeat="subject in subjects" ng-style="{'background-color': getgrade(student.name, subject) >= 50 ? '#0affda' : 'red'}">
{{ getgrade(student.name, subject) || '-' }}
</td>
</tr>
</tbody>
</table>
controller code
$scope.selectedYear = '';
$scope.selectedMonth = '';
$scope.selectedClass = '';
$scope.selectedSubject = ''; // إضافة المادة المختارة
$scope.getGradee = function() {
if ($scope.selectedYear !== '' && $scope.selectedMonth !== '' && $scope.selectedClass !== '') {
var subj = "api/getgrade.php?year=" + $scope.selectedYear + '&month=' + $scope.selectedMonth + '&class=' + $scope.selectedClass;
// إذا تم اختيار المادة، أضفها إلى URL
if ($scope.selectedSubject !== '') {
subj += '&subject=' + $scope.selectedSubject;
}
$http.get(subj)
.then(function(response) {
var data = response.data;
// تجميع البيانات حسب الطالب والمادة
var groupedData = {};
angular.forEach(data, function(entry) {
var key = entry.name + '-' + entry.subject;
if (!groupedData[key]) {
groupedData[key] = {
name: entry.name,
subject: entry.subject,
grade: 0 // اجمع الدرجات إذا لزم الأمر
};
}
groupedData[key].grade += entry.grade; // اجمع الدرجات بنفس المفتاح
});
// تحويل البيانات المجمعة إلى مصفوفة
$scope.students = Object.values(groupedData);
// الحصول على قائمة المواضيع دون تكرار
$scope.subjects = [];
angular.forEach($scope.students, function(student) {
if ($scope.subjects.indexOf(student.subject) === -1) {
$scope.subjects.push(student.subject);
}
});
});
}
};
$scope.getgrade = function(name, subject) {
var student = $scope.students.find(function(s) {
return s.name === name && s.subject === subject;
});
return student ? student.grade : '';
};
</code>
<code><table class="table table-bordered table-hover" style="font-size:18px">
<thead>
<tr style="font-size: 20px; font-weight: bold">
<th>Name</th>
<th ng-repeat="subject in subjects">{{ subject }}</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="student in students">
<td>{{ student.name }}</td>
<td ng-repeat="subject in subjects" ng-style="{'background-color': getgrade(student.name, subject) >= 50 ? '#0affda' : 'red'}">
{{ getgrade(student.name, subject) || '-' }}
</td>
</tr>
</tbody>
</table>
controller code
$scope.selectedYear = '';
$scope.selectedMonth = '';
$scope.selectedClass = '';
$scope.selectedSubject = ''; // إضافة المادة المختارة
$scope.getGradee = function() {
if ($scope.selectedYear !== '' && $scope.selectedMonth !== '' && $scope.selectedClass !== '') {
var subj = "api/getgrade.php?year=" + $scope.selectedYear + '&month=' + $scope.selectedMonth + '&class=' + $scope.selectedClass;
// إذا تم اختيار المادة، أضفها إلى URL
if ($scope.selectedSubject !== '') {
subj += '&subject=' + $scope.selectedSubject;
}
$http.get(subj)
.then(function(response) {
var data = response.data;
// تجميع البيانات حسب الطالب والمادة
var groupedData = {};
angular.forEach(data, function(entry) {
var key = entry.name + '-' + entry.subject;
if (!groupedData[key]) {
groupedData[key] = {
name: entry.name,
subject: entry.subject,
grade: 0 // اجمع الدرجات إذا لزم الأمر
};
}
groupedData[key].grade += entry.grade; // اجمع الدرجات بنفس المفتاح
});
// تحويل البيانات المجمعة إلى مصفوفة
$scope.students = Object.values(groupedData);
// الحصول على قائمة المواضيع دون تكرار
$scope.subjects = [];
angular.forEach($scope.students, function(student) {
if ($scope.subjects.indexOf(student.subject) === -1) {
$scope.subjects.push(student.subject);
}
});
});
}
};
$scope.getgrade = function(name, subject) {
var student = $scope.students.find(function(s) {
return s.name === name && s.subject === subject;
});
return student ? student.grade : '';
};
</code>
<table class="table table-bordered table-hover" style="font-size:18px">
<thead>
<tr style="font-size: 20px; font-weight: bold">
<th>Name</th>
<th ng-repeat="subject in subjects">{{ subject }}</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="student in students">
<td>{{ student.name }}</td>
<td ng-repeat="subject in subjects" ng-style="{'background-color': getgrade(student.name, subject) >= 50 ? '#0affda' : 'red'}">
{{ getgrade(student.name, subject) || '-' }}
</td>
</tr>
</tbody>
</table>
controller code
$scope.selectedYear = '';
$scope.selectedMonth = '';
$scope.selectedClass = '';
$scope.selectedSubject = ''; // إضافة المادة المختارة
$scope.getGradee = function() {
if ($scope.selectedYear !== '' && $scope.selectedMonth !== '' && $scope.selectedClass !== '') {
var subj = "api/getgrade.php?year=" + $scope.selectedYear + '&month=' + $scope.selectedMonth + '&class=' + $scope.selectedClass;
// إذا تم اختيار المادة، أضفها إلى URL
if ($scope.selectedSubject !== '') {
subj += '&subject=' + $scope.selectedSubject;
}
$http.get(subj)
.then(function(response) {
var data = response.data;
// تجميع البيانات حسب الطالب والمادة
var groupedData = {};
angular.forEach(data, function(entry) {
var key = entry.name + '-' + entry.subject;
if (!groupedData[key]) {
groupedData[key] = {
name: entry.name,
subject: entry.subject,
grade: 0 // اجمع الدرجات إذا لزم الأمر
};
}
groupedData[key].grade += entry.grade; // اجمع الدرجات بنفس المفتاح
});
// تحويل البيانات المجمعة إلى مصفوفة
$scope.students = Object.values(groupedData);
// الحصول على قائمة المواضيع دون تكرار
$scope.subjects = [];
angular.forEach($scope.students, function(student) {
if ($scope.subjects.indexOf(student.subject) === -1) {
$scope.subjects.push(student.subject);
}
});
});
}
};
$scope.getgrade = function(name, subject) {
var student = $scope.students.find(function(s) {
return s.name === name && s.subject === subject;
});
return student ? student.grade : '';
};
that is the problame
New contributor
العزي اليوسفي is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.