I have a Javascript object, that contains nested objects, but I can't seem to access the nested objects - the objects are formatted like:
Object
0: Object
colour: Object
colour: value
element: value
kelvin: Object
colour: value
element: value
status: Object
state: value
element: value
1: Object
colour: Object
colour: value
element: value
kelvin: Object
status: Object
When I stringify the parent object, it doesn't include the nested objects:
{"0":{},"1":{},"2":{},"3":{},"4":{},"5":{}}
Can anyone help me identify what I'm doing wrong?
Thanks in advance!
Here is the code where I'm having issues:
function updateStatus()
{
var triggers = {};
counter = 0;
$.when(
$("form[type='light_status']").each(function(f){
var options = {};
form = $(this);
selector = form.attr('selector');
id = form.attr('id');
$.ajax({
url: '/status/' + selector + '/' + id,
method: 'GET',
success: function(data) {
var data = $(data)[0];
var switchInput = '#'+data.selector+'-'+data.id;
if(data.status == 'on')
{
options.status = {element: switchInput, state: true};
}
else
{
options.status = {element: switchInput, state: false};
}
options.colour = {element: '#'+data.id+'-colourpicker', colour: data.colour};
options.kelvin = {element: '#'+data.id+'-kelvinpicker', colour: data.colour};
}
});
triggers[counter] = options;
counter++;
})
).done( function() {
console.log(triggers); //can see all nested objects
console.log(triggers[0].colour); //returns null
console.log('triggers:' + JSON.stringify(triggers)); // can only see parent object
});
}