nickhumble
2 years agoNew Contributor II
Using $.get on properties with forward slash
Hi,
We have an array of the following structure:
{
"/position/fte": {
"humanReadable": "100",
"value": 100
},
"/position/field_2354914": {
"humanReadable": "ALQhtani & Partners",
"value": "257532069"
},
"/position/field_2355402": {
"humanReadable": "fhdfhjf",
"value": "fhdfhjf"
},
"/position/field_7424424": {
"humanReadable": "Indirect",
"value": "257905227"
},
"/position/field_2355398": {
"humanReadable": "Central Operations",
"value": "257475809"
},
"/position/field_7424427": {
"humanReadable": "Support",
"value": "257905230"
},
"/position/job": {
"humanReadable": "Information Technology \\ 2a",
"value": 4807663
},
"/position/name": {
"humanReadable": "P-1486729",
"value": "P-1486729"
},
"/position/field_2355401": {
"humanReadable": "Birmingham - Snow Hill",
"value": "257529525"
},
"/position/department": {
"humanReadable": "Legal Operations",
"value": "257475756"
},
"/position/field_2355404": {
"humanReadable": "Hybrid Worker",
"value": "257781843"
},
"/position/field_7424426": {
"humanReadable": "Support",
"value": "258131652"
},
"/position/site": {
"humanReadable": "England",
"value": 2477909
},
"/position/field_7424425": {
"humanReadable": "Support",
"value": "258046626"
},
"/position/field_2355400": {
"humanReadable": "Audit - Australia",
"value": "257476016"
},
"/position/field_2355399": {
"humanReadable": "Business Services",
"value": "257475770"
}
}
Not all of the items in the array have the same properties, so I've been looking at using $.get to workaround this. However using something like:
$.get("['/position/field_7424425'].value")
always returns null.
I can use $.hasPath("['/position/field_7424425'].value") to check if it exists and it correctly returns true/false so can use a ternary operator but would prefer to use .get if possible.
Can anyone advise?
Thanks koryknick - this might just be the simplistic genius i was looking for!