Results 1 to 3 of 3

Thread: Appending nodes to Tree Panel and accessing custom data

  1. #1
    Sencha User
    Join Date
    Feb 2011
    Posts
    66
    Answers
    6

    Default Answered: Appending nodes to Tree Panel and accessing custom data

    We're upgrading from 4.0.7 to 4.1.

    I have an Ext.tree.Panel where I'm building the nodes dynamically. In 4.0.7 I was able to do something like the following:

    Code:
    myTree.getRootNode().appendChild({
      text: 'hello', 
      leaf: true,
      typeId: someId,
      definition: {prop1: 'a', prop2: 'b'}  // some custom data I want accessible later
    });
    Later, in a select node callback, I could receive the selected node and inspect the 'definition' property.

    In 4.1 I'm no longer able to access these custom properties, .e.g "definition". It appears as if the object passed to appendChild needs to be a "model". Since it's not a model, it's converted to one. In this conversion a data property is created, but my custom property is not added. This seems due to a predefined list of field names, e.g text, parentId, etc.

    How do I append this child node and have access to my custom property as I did in 4.0.7?

    Thanks,
    Jim

  2. There are some solutions for this issue:

    1. Add 'definition' as a field in your model definition
    Code:
    fields: [{
        ...
    },{
        name: 'definition', type: 'auto'
    }]
    ...
    2.
    Code:
    var node = myTree.getRootNode().appendChild({
    	text: 'hello', 
    	leaf: true,
    	typeId: someId,
    	// definition: {prop1: 'a', prop2: 'b'}  // some custom data I want accessible later
    });
    node.definition = {prop1: 'a', prop2: 'b'};
    To access custom data
    Code:
    var definition = <node>.definition;

  3. #2
    Sencha User
    Join Date
    Jan 2012
    Posts
    1,376
    Answers
    347

    Default

    There are some solutions for this issue:

    1. Add 'definition' as a field in your model definition
    Code:
    fields: [{
        ...
    },{
        name: 'definition', type: 'auto'
    }]
    ...
    2.
    Code:
    var node = myTree.getRootNode().appendChild({
    	text: 'hello', 
    	leaf: true,
    	typeId: someId,
    	// definition: {prop1: 'a', prop2: 'b'}  // some custom data I want accessible later
    });
    node.definition = {prop1: 'a', prop2: 'b'};
    To access custom data
    Code:
    var definition = <node>.definition;

  4. #3
    Sencha User
    Join Date
    Feb 2011
    Posts
    66
    Answers
    6

    Default

    Hi, thanks for the suggestions. I went with suggestion #2 and that worked. I appreciate it

    Jim

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •