adding to json property that may or may not exist yet
Posted
by mmcgrail
on Stack Overflow
See other posts from Stack Overflow
or by mmcgrail
Published on 2010-03-26T18:58:32Z
Indexed on
2010/03/26
19:03 UTC
Read the original article
Hit count: 468
let say i want to do this
var dasboard = {};
$('.check').click(function(){
$(this).toggleClass("active").siblings().slideToggle('slow', function() {
dashboard['pages']['pagename'][$(this).closest('li').attr("id")]['show'] = $(this).is(":hidden") ? 'collapsed' : 'expanded';
});
}
i get an error saying 'dashboard.pages is undefined'
is there away to dynamically add 'pages' and the children that follow without having to do the work of checking to see if it is defined first then if its not doing
dashboard['pages'] = {};
because sometimes they may already exist and I don't want to have to inspect the tree first i just want to build the branches as needed
© Stack Overflow or respective owner