[CLOSED] Javascript add treenode

  1. #1

    [CLOSED] Javascript add treenode

    I am migrating from v08.2 to v3 in the the old version to add a treenode I used to use the following code
     var node = new Ext.tree.TreeNode({
                                text: stMenu.reader.jsonData[i].Client,
                                id: stMenu.reader.jsonData[i].IDClient,
                                expandable: true
                            });
                            });
    I changed the code to the following
     var node = new Ext.tree.TreeNode({
                                text: App.stMenu.data.items[i].data.Client,
                                id: App.stMenu.data.items[i].data.IDClient,
                                expandable: true
                            });
    But it does not like TreeNode. Can someone please assist me. I need to know how to add a new treenode through javascript

    Thanks
    Last edited by Daniil; Mar 24, 2015 at 10:52 AM. Reason: [CLOSED]
  2. #2
    Hi @Richardt,

    Please use:
    var destinationNode = App.TreePanel1.getRootNode(); // for example, the root node
    
    destinationNode.appendChild({ 
        text: "New Node", 
        leaf: true 
    });
    Tip. If you migrate from v1 to v3, then both the Breaking Changes documents - v2 and v3 - are worth to review.
    https://examples2.ext.net/#/Getting_...EAKING_CHANGES
    https://examples3.ext.net/#/Getting_...EAKING_CHANGES
    Last edited by Daniil; Mar 24, 2015 at 11:26 AM.
  3. #3
    It is working. Will go through the changes
  4. #4
    <!DOCTYPE html>
    <html>
    <head runat="server">
        <script type="text/javascript">
            var addRecord = function () {
    
                var record = { id: 99, ID: 99, Name: 'AAAA', LastName: 'BBBB' };
    
                var rootNode = App._trp.getRootNode();
    
                var node = rootNode.createNode(record);
                node.internalId = record.ID.toString();
                node = rootNode.appendChild(record, false, true);
                node.set('leaf', true);
    
                App._str.sort();
            }
        </script>
    </head>
    <body>
        <ext:ResourceManager Theme="Crisp" runat="server" />
        <ext:TreePanel ID="_trp" RootVisible="false" Title="Ext.Net" Border="true" Width="300" Height="300" runat="server">
            <Store>
                <ext:TreeStore ID="_str" runat="server">
                    <Proxy>
                        <ext:AjaxProxy Url="~/Example/LoadTreeFakeChildren">
                            <Reader>
                                <ext:JsonReader RootProperty="data" />
                            </Reader>
                        </ext:AjaxProxy>
                    </Proxy>
                    <Model>
                        <ext:Model runat="server">
                            <Fields>
                                <ext:ModelField Name="Name" />
                                <ext:ModelField Name="LastName" />
                            </Fields>
                        </ext:Model>
                    </Model>
                </ext:TreeStore>
            </Store>
            <Root>
                <ext:Node NodeID="0" Text="Root" />
            </Root>
            <ColumnModel>
                <Columns>
                    <ext:TreeColumn Text="Name" DataIndex="Name" Flex="2" runat="server" />
                    <ext:Column Text="LastName" DataIndex="LastName" runat="server" />
                </Columns>
            </ColumnModel>
            <Buttons>
                <ext:Button Text="Add Record" runat="server">
                    <Listeners>
                        <Click Handler="addRecord();" />
                    </Listeners>
                </ext:Button>
            </Buttons>
        </ext:TreePanel>
    </body>
    </html>
    namespace SandBox.Controllers
    {
        public class ExampleController : System.Web.Mvc.Controller
        {
            public ActionResult Index()
            {
                return View();
            }
    
            public StoreResult LoadTreeFakeChildren()
            {
                NodeCollection nodes = new NodeCollection(false);
    
                for (int index = 1; index < 6; index++)
                {
                    Node no = new Node();
                    no.NodeID = index.ToString() + DateTime.Now.Second;
                    no.CustomAttributes.Add(new ConfigItem { Name = "Name", Value = string.Format("Name - {0}", no.NodeID), Mode = ParameterMode.Value });
                    no.CustomAttributes.Add(new ConfigItem { Name = "LastName", Value = string.Format("Last Name - {0}", no.NodeID), Mode = ParameterMode.Value });
                    nodes.Add(no);
                }
    
                return new StoreResult { Data = nodes.ToJson() };
            }
    
        }
    }

Similar Threads

  1. [CLOSED] How can I select a TreeNode using JavaScript code
    By gets_gui in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Oct 18, 2012, 10:05 PM
  2. TreeNode Javascript Events
    By markrobotnik in forum 2.x Help
    Replies: 3
    Last Post: Apr 18, 2012, 9:08 AM
  3. using javascript add a new treenode to a treegrid
    By huchaonian in forum 1.x Help
    Replies: 3
    Last Post: Oct 14, 2010, 9:32 AM
  4. Replies: 0
    Last Post: Dec 10, 2009, 11:14 AM
  5. How to get selected TreeNode in JavaScript?
    By dbassett74 in forum 1.x Help
    Replies: 1
    Last Post: May 26, 2009, 1:34 PM

Posting Permissions