I would like to know how to obtain in angular js the parallels of each matter. So far I can get the name but not its parallel. Could you help me? I have the following JSON:
[
{
"num": "125",
"nom_coe": "Matematicas",
"variacion": " ",
"creditos": "2",
"grupo_creditos": "",
"paralelos": [
{
"paralelo": "B",
"dia": "s/d",
"aula": "NO ASIGNADA",
"hora_inicio": "12:00:00",
"hora_fin": "12:00:00"
}
]
},
{
"num": "855",
"nom_coe": "Historia",
"variacion": " ",
"creditos": "4",
"grupo_creditos": "Genérica",
"paralelos": [
{
"paralelo": "A",
"dia": "Martes",
"aula": "NO ASIGNADA",
"hora_inicio": "10:00:00",
"hora_fin": "13:00:00"
}
]
},
{
"num": "255",
"nom_coe": "Lengua",
"variacion": " ",
"creditos": "3",
"grupo_creditos": "",
"paralelos": [
{
"paralelo": "A",
"dia": "Jueves",
"aula": "NO ASIGNADA",
"hora_inicio": "07:30:00",
"hora_fin": "10:00:00"
}
]
}
]
This is my code:
$scope.datosComp=data;
var length = $scope.datosComp.length;
for ( i=0; i < length; i++) {
alert($scope.datosComp[i].nom_coe);
};
How do I get the parallels?
Angular has a
angular.forEach
. This method calls the function it receives for each element in the array and passes the element in question as a parameter.How's it going
If I understand your question correctly you can try something like the following (for example if you are going to display it in the
.html
):http://fiddle.jshell.net/44ayLk16/
If I wanted the start time, for example, I would just have to use something like this:
Setting that you use
.nom_coe
could be something like this:http://fiddle.jshell.net/aj0hvdmw/