example: http://jsfiddle.net/yeehawjared/bawv0790/
I'm building an app where a webpage opens, loading JSON of a large data tree structure. TreeModel.js parses this great and all is well.
As time continues, the browser receives updates in the form of smaller data trees. I'm trying to wrap my head around combining the additionalData
to the masterTree
. I can't think of a way to simultaneously walk both and do a node-by-node comparison. If I could, it would be easy to aggregate node.model.x
properties and add children if they don't exist.
In the code below, I walk through the additional data - but I don't know how to efficiently combine new nodes to the masterTree
. Can someone help my methodology with psuedo-code or point me in the right direction? What's the best way to continually update my masterTree
?
Many thanks.
var tree = new TreeModel();
var masterTree = tree.parse(data1);
var additionalData = tree.parse(data2);
additionalData.walk(function (node) {
// compare additionalData to the masterTree
if (node.model.id == masterTree.model.id) {
console.debug('match, combine the attributes')
} else {
// add the additional node to the materTree
}
});