Is the branch of ExtJS 4.1 TreeStore lazy loading extending?

I am working on implementing lazy loading of tree branches in an MVC application using extjs4.1. The branches are located on different URLs and I have faced several challenges along the way. Unfortunately, at this point, the branching functionality is not working as expected.

Here is where I am encountering issues:

Ext.define('OI.view.tree.Tree' ,{
    extend: 'Ext.tree.Panel',
    alias : 'widget.treepanel',
    store: 'TreeStore',
    collapsible: true,
    rootVisible: false,

    viewConfig: {
        plugins: [{
            ptype: 'treeviewdragdrop'
        }]
    },
    height: 350,
    width: 400,
    title: 'Directory Listing',

    initComponent: function() {
        this.store = Ext.data.StoreManager.lookup(this.store);
        this.store.getProxy().url = 'data/level1.json'; // <-- initialization loading
        this.store.load();
        this.callParent(arguments);
    },

    listeners: {
        itemclick: function(view, record) {

            console.info('ID: '+record.get('id'));
            console.info('TEXT: '+record.get('text'));
            console.info('PrimType: '+record.get('primaryType'));
            console.info(record.fields.getCount());
            console.info('JCRPATH: '+record.get('jcrPath'));

            var newBranchStore = Ext.create('Ext.data.TreeStore', {
                model: 'OI.model.Branch',
                autoLoad: true,
                proxy: {
                    type: 'ajax',
                    reader: {
                        url: 'data/'+ record.get('jcrPath') +'/level1.json', //<-- load json at the level of the URL path returned by the model
                        type: 'json'
                    }
                },  
                folderSort: false
            });

            newBranchStore.load({url: 'data/'+ record.get('jcrPath') +'/level1.json',
                callback: function(){
                    console.log('loaded');
                    var mynode = newBranchStore.getNodeById('content_mytest');
                    console.info(mynode.get('id'));
                    this.store.getNodeById(record.get('id')).appendChild(mynode).expand(); // <-- this does not work
                },
                scope: this
            });
        }
    }
});

The initial level loads correctly, but when I click on a node, the correct JSON data is retrieved from the server (in this case, a static JSON file for debugging purposes). I then attempt to fetch a node statically and append it to the clicked node, however, this action is not successful.

My ultimate goal is to append all children obtained from the JSON file to the clicked node.

Furthermore, I am a bit uncertain about TreeStores... Am I right in assuming that only ONE TreeStore can be associated with one tree? Therefore, I need to add the new nodes to the original TreeStore... I could use some guidance and clarification on this matter.

Answer №1

Your current approach seems to be overly complex. A simpler alternative is to replace the URL of your store with the correct one before it loads:

Ext.define('OI.view.tree.Tree' ,{
    extend: 'Ext.tree.Panel',
    alias : 'widget.treepanel',
    store: 'TreeStore',
    collapsible: true,
    rootVisible: false,

    viewConfig: {
        plugins: [{
            ptype: 'treeviewdragdrop'
        }]
    },
    height: 350,
    width: 400,
    title: 'Directory Listing',

    initComponent: function() {
        this.store = Ext.data.StoreManager.lookup(this.store);
        this.store.getProxy().url = 'data/level1.json'; // <-- initial loading
        this.store.load();
        this.callParent(arguments);
    },

    listeners: {

        beforeload: function(store, operation) {
            store.getProxy().url = 'data/'+ operation.node.get('jcrPath') +'/level1.json';
        }
    }
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Encountering an error where property 'onClicked' is not defined when attempting to utilize chrome.action or chrome.browserAction in Chrome

I am currently developing a Chrome extension that will automatically redirect me to a specific URL when I click on the browser action icon. Here is the code snippet that I am trying to implement: chrome.browserAction.onClicked.addListener However, I am ...

What is the best way to send an array of strings through an AJAX call?

Utilizing ajax to send an array of strings to another page has been a bit tricky for me. Here is the array located on nomes.php [ 'Home','A empresa','funcionarios','Quem Somos?','Historia','Inicio&ap ...

"Combining the power of Angularjs and the state

I've been delving into Redux, mainly in the context of using it with React. However, I use AngularJS. Is there a compelling advantage to implementing Redux instead of handling state within AngularJS scope and letting Angular manage the bindings? ...

Sharing data between controllers using factory in AngularJS is not supported

I attempted to share data between two controllers by using a factory. However, it seems that the data is not being shared properly between the two inputs. In the AppCtrl controller, I set Data.FirstName to be equal to lattitude. But when I switch over to ...

Breaking down an object's data in a React component

I need to figure out how to properly extract variables and props from this code snippet: const MyComponent = (props, {data}) => { return ( <div data-set={props["data-set"]}> {data.name} </div> ) }; ...

The Cascading of Bootstrap Card Designs

Looking for some assistance with my TV Show Searcher project that is based on an API. The functionality is complete, but I'm struggling to get the Bootstrap cards to stack neatly without any empty space between them. I want it to resemble the image ga ...

Linking two socket.io clients together (Establishing a direct socket-to-socket connection that works across different browsers)

Can a direct P2P connection be established between two browsers using socket.io-client, bypassing the node.js server they are currently connected to? If possible, how? The goal is for clients A and B to communicate directly without going through the node. ...

The Jquery onclick function is executing multiple times, with each iteration increasing in

I have encountered an interesting problem that I can't seem to resolve. The issue involves dataTables and the data that is retrieved via jQuery ajax post after a selection change on a select element. Furthermore, I have an onclick function for multipl ...

`Is there a way to sort a deeply nested object by its values?`

I need assistance sorting an array of hospitals based on the lowest value of the amountinINR key, especially when dealing with deeply nested arrays of hospital objects. Does anyone know how to achieve this without using third-party libraries like lodash or ...

Why does jQuery val() function fail to clear readonly input date in Firefox but succeed in Chrome?

When using JQuery.val(''), I noticed a difference in behavior between Firefox and Chrome. You can see the issue demonstrated in this jsfiddle: https://jsfiddle.net/mdqfbj/d4eovkg8/3/ A JS function triggered by a radio button is supposed to clea ...

Discover the magic of TransformToggle and slideToggle in Javascript, HTML, and CSS

Working on a website coding project and ran into an issue. Trying to utilize an img as a link to slideToggle content. It's working, but I'd like the img to rotate 90deg on the first click and -90deg on the second one. Any solutions are greatly ap ...

The functionality of the button is affected when it is placed on the same line as a h1 heading

My goal is to have the page title and profile button aligned on the same line in the header of each page. However, I've encountered an issue where the button doesn't function properly when placed on the same line but works fine when separated ont ...

Customize the border style for the span element

I attempted to use the code below in JavaScript/jQuery to adjust the border thickness. Unfortunately, it seems to be ineffective. Can someone please assist me? //$("span").css({"border":"4px solid green"}); document.getElementById("192.168.42.151:8984_ ...

What is the best method to verify a string against a set of approved characters using JavaScript?

I have written some code that sanitizes user input to allow only alphanumeric characters and hyphens. Here is the code snippet: https://jsfiddle.net/py4pnr0L/ const inputValue = 'GHJHlk;sxa787BVK'; const sanitizedValue = inputValue.toLowerCase( ...

The Vue select change event is being triggered prematurely without any user interaction

I am facing an issue with my Vue app where the change event seems to trigger even before I make a selection. I tried using @input instead of @change, but encountered the same problem as described below. I have tested both @change and @input events, but th ...

Implementing a time to live feature in socket.io can be accomplished by setting a

After extensive searching online, I haven't been able to find any resources on how to implement the 'time-to-live' function using Socket.io. In my project, I am utilizing Node.js with express. The functionality of the mentioned time-to-live ...

Whenever I clear the contents of the datatable, I notice that 2 thead elements

I am facing an issue with a table that I populate using jQuery's .append() function and then initialize it as a datatable. Since the data is not fetched via an ajax call, I clear both the tbody and thead using .empty(). However, I encounter a problem ...

The conversion of a 2D json array into a string is mistakenly performed

On hand is an outer array that contains 2 arrays within it, making it a 2-dimensional array. This is how the array is initialized: $outerArray = array(); $nestedArray = array("first", "second", "third", "fourth"); $outerArray[] = $nestedArray; $nest ...

Retrieving data via AJAX from an SD card

I am using the Atmel SAM4E-EK microcontroller as a server to host a webpage and send data over HTTP protocol. I am currently facing an issue with the download function while trying to download a file from my sd_card, which will not be larger than 512MB. s ...

Selecting a full table row activates a top-up popup

I have successfully implemented a script in Javascript to enable full table row selection as shown below. <script type="text/javascript"> $(function() { $('#link-table td:first-child').hide(); $('#link-table tr').hover(func ...