代码之家  ›  专栏  ›  技术社区  ›  Mehrdad

动态设置AttributesObject

  •  1
  • Mehrdad  · 技术社区  · 10 年前

    如果我为树面板项设置了此选项:

    nodeItem.AttributesObject = new { c0 = 11111, c222 = 100000, c444 = 200000 };
    

    一切正常,但我需要动态设置AttributesObject。我的意思是列是动态的,所以我不知道编译时的属性名。

    当我使用这个时:

    var propertyValues = new Dictionary<string, int>();
    .....
    nodeItem.AttributesObject = propertyValues;
    

    它不起作用。 我该怎么做?

    1 回复  |  直到 10 年前
        1
  •  1
  •   Daniil Veriga    10 年前

    您可以使用System.Reflection创建具有动态财产的对象。

    或者使用节点的CustomAttributes。

    Ext.Net.Node node = new Ext.Net.Node();
    
    node.CustomAttributes.Add(new ConfigItem("c0", "11111", ParameterMode.Raw));
    node.CustomAttributes.Add(new ConfigItem("c222", "100000", ParameterMode.Raw));