开发者

Limit Child length in Extjs Tree

I want to limit the length of a child node to 20 cha开发者_开发百科racters,something like xxxxxxxxxxxxxxxxxxxx...

The data for tree would be coming from database in Json format. Here is my code.

Ext.onReady(function(){

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(); });


In order to do this, you'll need define a custom tree loader and override the createNode function:

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'
    }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜