I have this object and a I need to get the value of property name to assign it to a variable so that I can use it for each option in a menu. Here is the data returned:
“parentArrayOfObjects”: [
{
“data”: {
“current”: {
“id”: 0,
“name”: “Winter”
}
}
},
{
“data”: {
“current”: {
“id”: 0,
“name”: “Spring”
}
}
}
]
Using the above, I’m getting the same value for the data.current.name property for each menu at index 0, and that isn’t what I want. Please tell me what I'm doing wrong. Thanks.
// returns same name in all menus
var getCurrentChildPropertyName = (function(){
for (var value in parentArrayOfObjects) {
var currentChildProperty=parentArrayOfObjects[value].data.current;
if( currentChildProperty !== null){
return currentChildProperty.name;
}
}
})();
// returns same name in all menus
var getCurrentChildPropertyName = (function(){
for ( var i = 0; i < parentArrayOfObjects.length; i++) {
var currentChildProperty = parentArrayOfObjects[i].data.current;
if( currentChildProperty !== null){
return currentChildProperty.name;
}
}
})();
// Use different returned name in each menu (ExtJs3)
dataStore.insert(0, [new Ext.data.Record({
id: 0,
name: getCurrentChildPropertyName
})
returning when you find a match, which will end the execution of the function and return the value immediately.