I am looking at a JSON object structured like this :
{
"Name": "Shivansh",
"RollNo": "1",
"Stream": "CSE",
"OverallScore": "76",
"Semester": [
{
"SemesterName": "FY-2012 - 1",
"TotalScore": "78.00",
"StartDate" : "2012-02-14",
"EndDate" : "2012-07-16",
"Amount" : "55000",
"Subject": [
{
"subjectname": "maths",
"score": "81"
},
{
"subjectname": "chemistry",
"score": "79"
},
{
"subjectname": "physics",
"score": "77"
}
]
},
{
"SemesterName": "FY-2013-1",
"TotalScore": "76.00",
"StartDate" : "2013-02-16",
"EndDate" : "2014-07-16",
"Amount" : "55000",
"Subject": [
{
"subjectname": "ADA",
"score": "80"
},
{
"subjectname": "Operating System",
"score": "77"
},
{
"subjectname": "Databases",
"score": "73"
},
{
"subjectname": "Economics",
"score": "71"
}
]
}
]
}
Now I want to insert another semester field into this JSON using angularJS
. Is there anyone who can guide me on how to achieve this? The new semester field that needs to be added could look something like this:
{
"SemesterName": "FY-2013-2",
"TotalScore": "75.00",
"StartDate" : "2011-02-16",
"EndDate" : "2012-07-16",
"Amount" : "55067800",
"Subject": [
{
"subjectname": "Sets and Probability",
"score": "78"
},
{
"subjectname": "Networking and Security",
"score": "76"
},
{
"subjectname": "Advanced DataBases",
"score": "72"
},
{
"subjectname": "Economics-2",
"score": "70"
}
]
}
Currently, my controllers have this structure:
$scope.addRowSubject = function() {
$scope.insertsub = {
//id = $scope.getSubject.length+1;
subjectname : '1',
score : '1'
};
$scope.getSubject.push($scope.insertsub);
};
getSubject
represents the list of subjects within one semester field. This list can be accessed without any issues.
$scope.addRowSemester = function() {
$scope.insertsem = {
//id = $scope.getSemester.length+1;
StartDate : "1",
EndDate : "1",
Amount : "1",
SemesterName : "1",
TotalScore : "1",
Subject : ""
}
$scope.getSemester.push($scope.insertsem);
};
getSemester
holds the list of Semesters for a student.
Although I can successfully add a semester field to my JSON, the Subject field remains null
preventing me from adding subjects. Any suggestions on this issue would be appreciated.
Thank you in advance.