【问题标题】:Extjs: How to change tree node attributes?Extjs:如何更改树节点属性?
【发布时间】:2009-10-07 18:36:53
【问题描述】:

如何更改树节点的属性?

一个树节点具有以下属性:

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

现在我的脚本收到以下数据

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

我尝试更新属性(已更新):

// 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];
}

但是,树没有更新。

如何让树显示更改? 我需要节点来更改现有属性并添加新属性。

感谢您的帮助!

【问题讨论】:

  • a.result.data.property 可能是访问它的不好方法.. 未定义

标签: javascript extjs


【解决方案1】:

来自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;        
    }
} 

如果您在更新循环之后调用它应该可以工作。

【讨论】:

  • 谢谢,但我试过了,它什么也没做。 Firebug 说不是 js 错误。
  • 我得到了这个工作。该函数更新了除文本列之外的所有列。为此我不得不使用 node.setText(a.result.data.description)
  • 谢谢老兄,这是纯金!你拯救了我的一天......现在可以是一个宁静的星期五:D
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-12-24
  • 1970-01-01
  • 1970-01-01
  • 2021-10-12
  • 1970-01-01
  • 2017-09-07
  • 1970-01-01
相关资源
最近更新 更多