Ext JS 4.2 add tree node
by Na Kwangheum
HTML
<link rel="stylesheet" href="http://cdn.sencha.io/ext-4.2.0-gpl/resources/css/ext-all.css">
<div id="treeList"></div>
JavaScript
Ext.require(['*']);
Ext.onReady(function(){
var addButton = Ext.create('Ext.Button', {
text: '노드 추가',
scale: 'large',
listeners: {
el: {
click: function() {
var nodeId = Ext.getCmp('tree').getRootNode().childNodes.length+1;
var rootNode = Ext.getCmp("tree").getRootNode();
var thisNode = rootNode.appendChild({
"id":nodeId
,"text":"페이지"+nodeId
,"leaf":true
});
Ext.getCmp("tree").selectPath(thisNode.getPath());
}
}
}
});
var store = Ext.create('Ext.data.TreeStore', {
id: 'store',
proxy: {
data :
[{
"id": 1,
"text": "페이지1",
"leaf": true
}, {
"id": 2,
"text": "페이지2",
"leaf": true
}, {
"id": 3,
"text": "페이지3",
"leaf": true
}, {
"id": 4,
"text": "페이지4",
"leaf": true
}, {
"id": 5,
"text": "페이지5",
"leaf": true
}, {
"id": 6,
"text": "페이지6",
"leaf": true
}, {
"id": 7,
"text": "페이지7",
"leaf": true
}, {
"id": 8,
"text": "페이지8",
"leaf": true
}, {
"id": 9,
"text": "페이지9",
"leaf": true
}, {
"id": 10,
"text": "페이지10",
"leaf": true
}, {
"id": 11,
"text": "페이지11",
"leaf": true
}, {
"id": 12,
...