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

Comparing elements in one array to elements in another array

In AngularJS, the $scope.categories array is populated from a multi-select element. $scope.categories = ["Adventure", "Strategy"] To compare this array with the categories in the items array below: $scope.items = [ { title: "Star Wars", ...

Retrieve data from an API and store it in a JSON array

My website is having an issue where it's fetching data from an API and displaying it in a table, but all the cells are returning undefined values. The data in the API is structured as an array with multiple datasets inside curly braces that I am unsu ...

How can I unselect a radio button by double clicking on it?

I am in need of a specific feature: When a user clicks on a radio button that is already checked, I want it to become unchecked. I've attempted to implement this code but unfortunately, it has not been successful. $(document).on('mouseup' ...

Vue-Router: Identified an ongoing redirection loop in a navigation guard while transitioning from the home page to the login page

I need to implement a feature where pages are blocked if there is no authentication token and users are redirected to the login page. I have two .ts pages (main and routes) routes: import { RouteRecordRaw } from 'vue-router'; const routes: Route ...

Unable to send parameters via URL when making an Ajax request in Rails

Struggling to pass a parameter through a URL in an Ajax request that's triggered by a confirmation dialog. Need the value of that parameter in my Rails controller upon successful request but can't seem to make it work. Tried the following code s ...

Is it redundant to use flatMap in RXJS?

I recently came across an enlightening article on RXJS which delves into the concept of flatMap. After understanding its purpose - to flatten observable of observables into a single observable sequence (similar to SelectMany in C#) - I noticed an interes ...

Callback function not being triggered in Jquery's getJson method

I am currently faced with a javascript conundrum. Below is the snippet of code that I have been working on: $.get("categories/json_get_cities/" + stateId, function(result) { //code here }, 'json' ); ...

Verify the user's activity status in the MySQL database using Node.js by checking the timestamp of their last login

I have a query regarding user activity and deletion from the database. I need to determine when a user last logged in to see if their account is inactive. Unfortunately, I am unsure of how to tackle this task or check for the last login time. If anyone c ...

Sending javascript data to php within a modal popup

I am currently working on passing a javascript variable to php within a modal window, all while remaining on the same page (edit.php). Although I plan to tackle handling this across separate pages later on, for now, I have successfully implemented the foll ...

The D3 force layout is currently displaying just a single connection

I've been experimenting with a graph that I found in this demo and now I want to modify it to display data from Spotify. I created a sample JSON file and adjusted the script accordingly for the new data format, everything seems to be working fine exc ...

Techniques for incorporating a variable into the value field in JavaScript

let y = data[1]; cell1.innerHTML ='<input id="text" type="text" value= "'y'"/>' ; This snippet of code does not render any content when attempting to pass the variable, but if you provide a specific value like "h", it will displa ...

Exploring the Brilliance of MVC PHP/AJAX

I am currently in the process of developing a PHP website that will showcase statistics derived from an external source. To illustrate how the MVC (Model-View-Controller) architecture will be implemented, I have created this unique diagram. As someone wh ...

Do not request for this element within the array

I have a function that applies to all elements in an array, except for the currently clicked one. For example: cubesmixed = [array, with, 145, elements] cubesmixed[54].click(function() { for(var i = 0; i < 145; i++) { var randomnumber=Math.flo ...

In what way can I decipher a section of the URL query string within my AngularJS application?

Here is a snippet of code that I am working with: var search = $location.search(); if (angular.isDefined(search.load) && search.load != null) { if (search.load = "confirmEmail") authService.confirmEmailUserId = search.userI ...

Creating a dynamically changing AppBar component in material-ui-next React that responds to scroll events

Following the Material Design guidelines, the top app bar should exhibit specific behavior: When scrolling, the top app bar can [...] undergo the following changes: - Scrolling upwards hides the top app bar - Scrolling downwards reveals the top ...

Attempting to save data to a .txt file using PHP and making an AJAX POST request

I have been facing an issue while trying to save a dynamically created string based on user interaction in my web app. It's just a simple string without anything special. I am using ajax to send this string to the server, and although it reaches the f ...

Require assistance in getting a slider operational

Hello there! I could really use your assistance with this code. I have been trying to make it work using JavaScript, but I'm determined not to incorporate any external JS files. Here is the snippet of JavaScript code I am working with: "use strict"; ...

TinyMCE generates HTML code with embedded tags

Hey there, I'm currently facing an issue with TinyMCE that I just can't seem to solve. I've browsed through some related posts but haven't found a solution that works for me... For example: When I input something in my back office, ...

Develop an outline using D3.js for the clipath shape

After successfully creating a shape with a color gradient, I encountered the need for further customization. If you are interested in this topic, check out these related questions: Add multi color gradient for different points in d3.js d3.js scatter plot c ...

Manipulating nested arrays using index values in JavaScript

Can someone assist me in sorting a multidimensional array based on the value of the first index? I've tried using a for loop without success. Looking for solutions in JS or jQuery. I want to convert the following array: var pinData = [ ['< ...