I am refactoring some code, and want to change an array of code/name objects to be named objects. I want to do this so I can use it for equality tests. The old way was to compare the code directly...
if(current.addressCode === "1"){ ... }
But I would prefer to do it like this...
if(current.addressCode === types.student.address.letter.code){ ... }
The old object looks like this...
student{
address: [
{code: "0", name: "Select proof of address"},
{code: "1", name: "Letter"},
{code: "3", name: "Photograph"}
],
id: [
{code: "0", name: "Select type of ID"},
{code: "1", name: "Passport"},
{code: "2", name: "Driving Licence"}
]
}
So I want my new object to look like this...
student: {
address: {
select: {code: "0", name: "Select proof of address"},
letter: {code: "1", name: "Letter"},
photograph: {code: "3", name: "Photograph"},
},
id: {
select: {code: "0", name: "Select type of ID"},
passport: {code: "1", name: "Passport"},
drivingLicense: {code: "2", name: "Driving Licence"},
}
}
Where I am stuck, is I don't know how to generate a select element in angular js from this object which used to be generated from the old structure like this...
<select ng-model="current.addressCode" ng-options="t.code as t.name for t in student.address"></select>
How can I use the new object to generate a select form element?