PDA

View Full Version : Associate each leaf of a tree panel to a separate model instance



dirtdevil
6 Aug 2012, 3:35 PM
For a tree.panel, can you associate each leaf with a model instance from a store? So for example, you had a tree of users and each user represents a model instance. If you remove a user leaf in the tree, you could easily remove it's associated model instance as well. Basically a way to fuse a model instance to a node instance in a tree.

scottmartin
8 Aug 2012, 7:43 PM
Sounds like voodoo to me .. but you never know ... Perhaps someone may ;)

Regards,
Scott.

evant
8 Aug 2012, 7:46 PM
Each node in the tree is a model. It gets decorated with NodeInterface to behave like a node, but it's a model instance.

scottmartin
8 Aug 2012, 8:05 PM
I hate when I misunderstand the question .. in a forum, in public .. :">

http://www.youtube.com/watch?v=WcZwoZskVMk

Scott.

dirtdevil
9 Aug 2012, 12:23 PM
1. How do I get to the model thats decorated? For example...
myNode.getModel()

2. Can I specify the model? For example


{
text: 'my leaf',
leaf: true,
modelType: 'mymodel'
}

evant
9 Aug 2012, 1:53 PM
The node ~is a~ model. It has all the model methods.

dirtdevil
9 Aug 2012, 7:00 PM
I took a crack at it and even though my code runs, I don't know if it worked or not. What do I access in the node to know if my custom model made it?

Do I just do a node.getModel.getFields() and estTime, allocTime etc etc will show up? I looked at the object that gets dumped to the console and tried to understand as much of the source from the docs.


Ext.define('ux.model.MyModel', {
extend: 'Ext.data.Model',
alias: 'model.book',
fields: ['id', 'name', 'estTime', 'allocTime','desc', 'dueDate']
});


Ext.define('ux.MyTree', {
extend: 'Ext.tree.Panel',
title: 'tasks',
requires: [
'ux.model.MyTreeModel'
],
columns: [{
xtype: 'treecolumn',
text: 'testing',
dataIndex: 'text',
flex: 4
}],
store: {
model: 'book',
root: {
text: 'All Books',
expanded: true,
id: 33333022323,
leaf: false,
children: [{
text: "Book 1",
id: 3333302444,
leaf: false
},{
text: "book 2",
id: 444440344444,
expanded: true,
}]
}
},
listeners: {
itemclick: function(a,b){
console.log(b);
}
}
});

dirtdevil
16 Aug 2012, 5:02 PM
I just wanted to say thanks. I made a sample app and after some firebugging, I know what you meant. Sorry, I must have had a brain fart.