Question

I want to associate custom data for each node in my TreePanel. Then i will use it in client-side.

Server side looks like:

        Ext.Net.Node root = new Node {Text = "Dummy Form"};
        root.AttributesObject = new { nodeType = "Form" };

        Ext.Net.Node section01 = new Node { Text = "Section 01" };
        section01.AttributesObject = new { nodeType = "Section" };

How can i access this AttributesObject in client-side?

Client side looks like:

    .Listeners(l =>
    {
       l.ItemClick.Handler = "myClickHandler(item,record,node,index,e)";
    }

I tried the followings:

  • item.nodeType
  • record.nodeType
  • node.nodeType
  • record.data.nodeType

None of above worked for me, each of them returns "undefined".

Was it helpful?

Solution

record.raw.[attributeFieldName] can be used for accessing data client-side.

For a click handler defined as below:

.Listeners(l =>
    {
       l.ItemClick.Handler = "myClickHandler(item,record,node,index,e)";
    }

Set attribute in server-side:

section01.AttributesObject = new { nodeType = "Section" };

Access custom set attribute in client-side:

function myClickHandler(item, record, node, index, e) {

    var nodeType = record.raw.nodeType;
    console.log(nodeType); //prints "Section"

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top