If you load from only one node at a time, it would make sense to only restore state in this one node. That's why I would do it in the function that knows the node that is loaded. That will be something like that then:
function() {
var store = tree.getStore(),
node = store.getNodeById('myTree/107'), // that's up to you here
ids = [];
function pluckCheckedIds(node) {
if (node.get('checked')) {
ids.push(node.getId());
}
node.eachChild(function(node) {
pluckCheckedIds(node);
});
}
// EDIT: forgot this line:
pluckCheckedIds(node);
// EDIT2: in order to save and restore the checked state for the whole
// tree (in order to load multiple nodes at once), you could use this
// line instead:
pluckCheckedIds(store.getRootNode());
store.load({
node: node,
callback: function(records, operation) {
if (operation.wasSuccessful) {
Ext.each(ids, function(id) {
var node = store.getNodeById(id);
if (node) {
node.set('checked', true);
}
});
}
}
});
}