View Full Version : How to compare Two Tree Store

9 Jul 2013, 7:55 PM
Is there a way in Sencha to compare the difference between two Tree Store/Tree Panel?

Background to this is we have like a Menu System wherein we have a Master Menu as we called it and all users were configured a menu based on the Master Menu, same structure, same sorting, the only difference is that some users menu will be hidden based on our permission settings.

Now, when we have changes on Master Menu such as adding, deleting or renaming, it should cascade down to all users without affecting their menu state/permission.

Note: Our back end store here is not in a relational manner but only a JSON string that comes from the actual Tree Store.

Hope you can give me idea on how to approach this. :)


11 Jul 2013, 1:53 PM
I don't know that there's an existing method to do what you're wanting to do, but I suspect you can write your own and I would think cascadeBy will come in handy to do your analysis:

11 Jul 2013, 9:51 PM
I "serialized" two objects for this with Ext.Object.toQueryString (http://docs.sencha.com/extjs/4.2.0/#!/api/Ext.Object-method-toQueryString)

equals: function(value1, value2)
var serializedArray1 = [],
serializedArray2 = [];

//In Array packen, wenn kein Array
if (false === Ext.isArray(value1)) {
value1 = [value1];
if (false === Ext.isArray(value2)) {
value2 = [value2];

Ext.Array.each(value1, function(value) {
Ext.Array.push(serializedArray1, Ext.Object.toQueryString(value, true));

Ext.Array.each(value2, function(value) {
Ext.Array.push(serializedArray2, Ext.Object.toQueryString(value, true));

return Ext.Array.equals(serializedArray1, serializedArray2);

Ext.define('Muh.library.Array', {
override: 'Ext.Array',
equals: function(array1, array2) {
var len1 = array1.length,
len2 = array2.length,

// Short circuit if the same array is passed twice
if (array1 === array2) {
return true;
if (len1 !== len2) {
return false;

for (i = 0; i < len1; ++i) {
if (array1[i] !== array2[i]) {
return false;
return true;

You would neet do collect the data from the trees first and build it up in deep objects:

//Recursion Loop ^^

But take care of things like leaf = false, because if you expand the tree nodes it will change the leaf value and the trees will be different :x

I used that logic for knowing when a tree is dirty.