My objects are really large and complex, but I'll do my best to summarize. I know th following code is not syntatically correct, but I hope you get the idea. If I were to run something like the following, I would expect to get a "copy" of my sub item from group 2 and then have that "copy" be altered an then pushed to group 1's sub items. The problem I'm seeing is that when I alter my sliced subitem it is not a real copy and thus when I alter it, it is changing the original array item that was sliced. I have gotten around this by stringifying my sliced object, parsing it, and then pushing it into my observable array.
Thanks for the help.
viewModel = kendo.observable({
groups: arrayOfGroups
});
arrayOfGroups = [
{item : { key :
'item 1'
, items : [{ key :
'sub item 1'
}]},
{item : { key :
'item 2'
, items : [{ key :
'sub item 2'
}, { key : 'sub item 3}]}
]
var
subItem2 = viewModel.get(
'groups[1]'
).items.slice(0,1);
subItem2.key =
'new sub item'
;
viewModel.get(
'groups[0]'
).items.push(subItem2);