我想将子节点的长度限制为20个字符,例如xxxxxxxxxxxxxxxxxxxx ......
树的数据将来自Json格式的数据库。这是我的代码。
Ext.onReady(函数(){
var Tree = Ext.tree;
var tree = new Tree.TreePanel({
useArrows: true,
autoScroll: true,
animate: true,
enableDD: true,
containerScroll: true,
border: false,
// auto create TreeLoader
dataUrl: 'test.json',
root: {
nodeType: 'async',
text: 'Ext JS',
draggable: false,
id: 'src'
}
});
// render the tree
tree.render('tree-div');
tree.getRootNode().expand(); });
答案 0 :(得分:3)
为此,您需要定义自定义树加载器并覆盖createNode
函数:
var tree = new Tree.TreePanel({
useArrows: true,
autoScroll: true,
animate: true,
enableDD: true,
containerScroll: true,
border: false,
loader: new Ext.tree.TreeLoader({
dataUrl: this.dataUrl,
createNode: function(attr) {
attr.text = attr.text.substr(0, 20);
Ext.tree.TreeLoader.superclass.createNode.call(this, attr);
}
}),
root: {
nodeType: 'async',
text: 'Ext JS',
draggable: false,
id: 'src'
}
});