我是 Extjs 的新手,我目前正在使用一棵树,我可以在其中创建一个分支,然后创建部分。我需要帮助来编辑我的代码的功能。
createSection:功能(按钮){ var node = button.up('menu').node;
if (node.data.leaf) {
return false;
}
node.expand();
var newSection = node.appendChild({
name: 'New section ' + "(" + (node.childNodes.length +1) + ")" ,
type: 'toc-by-system',
leaf: false,
id: uuid['v4'](),
children: [],
editor: {
xtype: 'textfield'
}
});
newSection.BeginEdit(),
},
请检查示例代码,以在单击按钮时以编程方式添加节点!
var store = Ext.create('Ext.data.TreeStore', {
root: {
expanded: true,
children: [{
id: 3,
text: 'detention'
}, {
text: 'homework',
id: 5,
expanded: true,
children: [{
text: 'book report',
id: 7,
leaf: true
}, {
text: 'algebra',
id: 9,
leaf: true
}]
}, {
text: 'buy lottery tickets',
id: 37,
leaf: true
}]
}
});
Ext.create('Ext.tree.Panel', {
title: 'Simple Tree',
itemId: 'menu',
tbar: [{
text: 'button',
handler(button) {
var treeNode = button.up('#menu').getRootNode();
if (treeNode.data.leaf) {
return false;
}
treeNode.expand();
treeNode.appendChild({
text: 'New section ' + ((treeNode.childNodes.length) + 1),
type: 'toc-by-system',
leaf: false,
children: [],
});
}
}],
width: 500,
height: 500,
store: store,
rootVisible: false,
renderTo: Ext.getBody()
});