For example consider following tree,
Parent1
- Child1
- Child2
- Child3
- Chld4
- Child5
Each node will have subtree models as associated model and using following function, you can convert modified tree nodes into associated-model store. This store is a plain store with associated models. Now you can send this model to the server
(For more info on sending updated model associations to the server viz following blog post
http://balu-learnings.blogspot.in/2014/03/extjs-4-sending-updated-models-to.html ).
model :
Ext.define('App.model.treegridsample', {
extend : 'Ext.data.Model',
fields : [ {
name : 'id',
useNull : true,
defaultValue : ''
}{
name : 'text'
}{
name : 'leaf',
persist : false
}],
associations : [ {
type : 'hasMany',
model : 'App.model.treegridsample',
name : 'children'
}
});
CustomTree.js
Ext.define('App.view.common.CustomTree', { extend : 'Ext.tree.Panel', convertToStore : function(model) { if (this.getStore() === null) { return null; } var rootNode = this.getStore().getRootNode(); model = model || Ext.getClassName(this.getStore().getRootNode()); dataStore = this.convertNodeToStore(rootNode, model); return dataStore.childrenStore; }, convertNodeToStore : function(rootNode, model) { var record = Ext.create(model); record.data = rootNode.data; if (record.childrenStore === null || typeof record.childrenStore === 'undefined') { record.childrenStore = Ext.create('Ext.data.Store', { model : model }); } for (var i = 0; i < rootNode.childNodes.length; i++) { var cNode = rootNode.childNodes[i]; var child = this.convertNodeToStore(cNode, model); if (cNode.dirty || cNode.phantom) { record.childrenStore.add(child); rootNode.setDirty(); } } return record; }
Source can be found@ https://github.com/Balagangadhar/ExtJS4-Misc/blob/master/CustomTree.js
No comments:
Post a Comment