PDA

View Full Version : Tree - how to set default leaf value



ondra.cz
24 Nov 2013, 2:04 PM
Hello,
I'm trying to set default value for model property, exactly for treestore's model property 'leaf' to true.
This code stoped worked for me since version 4.2.1:


Ext.define('Module.gallery.model.Album', {
extend : 'Ext.data.Model',

idProperty : 'albumId',

fields : [{
name : 'albumId',
type : 'int'
}, {
...
}, {
name : 'leaf',
type : 'boolean',
defaultValue : true,
persist : false
}]
...


Actually with this code the store can not be loaded at all (BUG?).

Thanks for any advice.

scottmartin
26 Nov 2013, 10:37 AM
You should be able to set checked: true/false in your data



"children": [{
"text": "Go jogging",
"leaf": true,
"checked": true
},{




Ext.application({
name : 'Fiddle',

launch : function() {

var store = Ext.create('Ext.data.TreeStore', {
root: {
expanded: true,
children: [
{ text: "detention", leaf: true },
{ text: "homework", expanded: true, children: [
{ text: "book report", leaf: true, checked: false },
{ text: "algebra", leaf: true, checked: true}
] },
{ text: "buy lottery tickets", leaf: true }
]
}
});

Ext.create('Ext.tree.Panel', {
title: 'Simple Tree',
width: 200,
height: 150,
store: store,
rootVisible: false,
renderTo: Ext.getBody()
});


}
});

ondra.cz
27 Nov 2013, 2:31 AM
Hi,
thank you for answer again ;)
Try this code in JSFiddle:


Ext.application({
name : 'Fiddle',

launch : function() {
Ext.define('Album', {
extend : 'Ext.data.Model',
idProperty : 'albumId',
fields : [{
name : 'albumId',
type : 'int'
}, {
name : 'text',
type : 'string'
}, {
name : 'leaf',
type : 'boolean',
defaultValue : true
}]
});

var store = new Ext.data.TreeStore({
model : 'Album',
proxy : {
type : 'ajax',
api : {
read : '/gallery/album/read'
},
actionMethods : {
read : 'POST'
},
reader : {
type : 'json',
root : 'children',
successProperty : 'success',
totalProperty : 'total',
messageProperty : 'message'
},
writer : {
type : 'json',
encode : true,
writeAllFields : false,
root : 'data',
allowSingle : false
}
},
root : {
expanded : true
}
});

Ext.create('Ext.tree.Panel', {
title: 'Simple Tree',
width: 200,
height: 150,
store: store,
rootVisible: false,
renderTo: Ext.getBody()
});
}
});

In this case, no ajax request is called. But if you remove model's "leaf" field or just change "defaultValue" to false, ajax query is called properly. With "defaultValue: true" no error is thrown, but the ajax request is not called either.
In ExtJS 4.1 everything works fain.

vadimk
18 Jun 2015, 7:19 AM
I guess that's because the root element is getting leaf : true as well, so the store is not loading items as there's no any parent with children.