最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Extjs: How to change tree node attributes? - Stack Overflow

programmeradmin2浏览0评论

How can I change the attributes of a tree node?

One tree node has the following attributes:

{"id":"75",
"description":"My Tree Node",
"status":"25"
"uiProvider":"col",
"leaf":true}

Now my script receives the following data

{
"id":"75",
"status":"100",
"cls":"done"
}

I try to update the attributes (UPDATED):

// a.result.data has the new data and taskID is the node's id
for (var property in a.result.data)
{ 
  tree.getNodeById(taskID).attributes[property] = a.result.data[property];
}

The tree, however, does not get updated.

How can I make the tree show the changes? I need the node to change existing attributes and add the new attributes.

I appreciate your help!

How can I change the attributes of a tree node?

One tree node has the following attributes:

{"id":"75",
"description":"My Tree Node",
"status":"25"
"uiProvider":"col",
"leaf":true}

Now my script receives the following data

{
"id":"75",
"status":"100",
"cls":"done"
}

I try to update the attributes (UPDATED):

// a.result.data has the new data and taskID is the node's id
for (var property in a.result.data)
{ 
  tree.getNodeById(taskID).attributes[property] = a.result.data[property];
}

The tree, however, does not get updated.

How can I make the tree show the changes? I need the node to change existing attributes and add the new attributes.

I appreciate your help!

Share Improve this question edited Oct 7, 2009 at 21:02 Alex L asked Oct 7, 2009 at 18:36 Alex LAlex L 8,4496 gold badges44 silver badges52 bronze badges 1
  • a.result.data.property might be a bad way to access it.. getting undefined – Alex L Commented Oct 7, 2009 at 20:51
Add a ment  | 

1 Answer 1

Reset to default 2

From the extjs forums:

function refreshNodeColumns(n)
{
    var t = n.getOwnerTree();
    var a = n.attributes;
    var cols = t.columns;
    var el = n.ui.getEl().firstChild; // <div class="x-tree-el">
    var cells = el.childNodes;

    //<div class="x-tree-col"><div class="x-tree-col-text">

    for(var i = 1, len = cols.length; i < len; i++)
    {
        var d = cols[i].dataIndex;
        var v = (a[d]!=null)? a[d] : '';
        if (cols[i].renderer) v = cols[i].renderer(v);
        cells[i].firstChild.innerHTML = v;        
    }
} 

Should work if you call it after your update loop.

发布评论

评论列表(0)

  1. 暂无评论