Elements in ExtJS Tree panel not displaying properly

I am currently working on a tree panel that displays data from a JSON file. When I expand one category, the elements display correctly. However, when I expand another category, the previously opened elements disappear. This issue persists with all elements in the expand and contract event.

Below are screenshots illustrating this behavior:

First expansion event:

Second expansion event:

Third expansion event:

Here is the code snippet that I am using:

The model:

Ext.define('app.model.modeloCapa', {
extend: 'Ext.data.Model',
fields: ['nombre','url'],

proxy: {
    type: 'ajax',
    url: "data/jsonprovisional.json",  
    reader: {
        type    : 'json',
        root    : 'Result',
    }
}});

The store:

Ext.define('app.store.capa', {
extend: 'Ext.data.TreeStore',
requires: 'app.model.modeloCapa',
model: 'app.model.modeloCapa'});

The view:

initComponent: function() {

    var screenWidth = window.screen.width;
    var screenHeight = window.screen.height;

    var tocWidth = 330;
    var tocHeight = 473;

    if (screenWidth <= 1024) {
        tocWidth = 282;
        tocHeight = 373;
    }
    var treeStore = Ext.getStore('capa');

    // Additional code for initializing the tree view 

    ... // Rest of the original code goes here

}

And the sample JSON data used in the application:

{"Result": [{
"nombre": "Componente Biótico y Abiótico",
"id": 1,
    "Result":[{
        "nombre": "Recursos hídricos",
        "id": 2,
            "Result": [/* Nested elements go here */]
    },{
        "nombre": "Fauna",
        "id": 3,
            "Result": [/* Nested elements go here */]
    },{
        "nombre": "Ecosistemas",
        "id": 4,
            "Result": [/* Nested elements go here */]
    }]},{
"nombre": "ARE",
"id": 5,
"Result":[{
        "nombre": "Minero Energético",
        "id": 2,
            "Result": [/* Nested elements go here */]
    }]},{
/* More nested data categories */
}]}

Answer №1

For TreePanel to function correctly, each node must have a distinct 'id' property.

Looking at your JSON data, it appears that nodes "Recursos hídricos," "Minero Energético," and "Cobertura y uso" all share the same id:

"nombre": "Recursos hídricos",
"id": 2

"nombre": "Minero Energético",
"id": 2

"nombre": "Cobertura y uso",
"id": 2

This explains why "Recursos hídricos" disappears when clicking on the "ARE" node. To resolve this issue, ensure that each node has a unique ID regardless of its level in the hierarchy.

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

What is the method for selecting the col/row or x/y coordinates for N random elements from a 2D matrix without repeating any items or coordinates?

In my dataset, which is a 2D matrix, here is an example: data = [["a", "b", "c", "d"], ["e", "g"], ["i", "j", "k"]] I am looking to retrieve N random (x, y) indexes without any duplicates. Previously, I had a similar question and here is the solution I f ...

How can we best optimize the conclusion of an infinite scroll when content is depleted?

Our web application has a feature that automatically loads more content when the bottom of the page is reached. Here's how it works: $window .on('scroll', function () { var $this = $(this) ; if ($this.scrollTop() == $do ...

Ways to verify the existence of a particular word within a nested array of objects

I have implemented a text input field and a send button for submitting the entered text. Utilizing the react-mention library, I am able to handle hashtags in the text. As the user types, if they include "#" it displays available hashtags from the data set. ...

Manually managing WebSocket overhead and buffering data packets by hand

Introduction: I understand that this query may pertain to premature optimization, but I kindly request to set that aside while responding. The project at hand involves developing a whiteboard-style program utilizing WebSockets, allowing only one individua ...

Tips for submitting a specific form

I am in need of submitting a form in a specific format, This is how I want it, as requested by the server to create a user with access: { "archived": false, "client": 1, "first_name": "Foo", "id": 5066549580791808, "inactive": false, ...

There was a serious issue: The mark-compacts were not working effectively near the heap limit, resulting in allocation failure - the JavaScript heap ran out of memory during the

I recently set up a t2.micro server on AWS and encountered an issue when running our application with the command "sudo npm start". The error message I received was: "FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript he ...

Waiting for Node/Express to process request

I'm fairly new to the world of Node.js and so far, it's been amazing. However, I've run into a minor issue while running node (with express) locally - Once I reach the 10th request, each subsequent one hangs and shows as Pending in the Chrom ...

Developing a php script to edit JSON files

I have a JSON file structured in the following way: { "data": { "Category": { "Product1": [{ "Code": "abc" }], "Product2": [{ ...

"Troubleshooting: Vue JS Axios Post Request Not Passing Data to PHP Server

After successfully uploading an image in Vue JS and sending a POST request to a Laravel Route, the JSON response from the API is displayed on the client side as expected. However, there seems to be an issue with retrieving this response in PHP, as it retur ...

IntelliSense in VSCode does not seem to be able to identify the SDL_image extension library when using

I'm facing an issue with including the SDL_image extension library to the SDL.framework in my project. Despite editing the c_cpp_properties.json file to make IntelliSense recognize the SDL framework, I keep getting error lines when trying to include # ...

Update the HTML table by changing the first cell in the first row to span multiple

I currently have a table structured like this: <table> <thead> <tr> <th></th> <th>Col1</th> <th>Col2</th> <th>Col3</th> <th>Col4& ...

Exploring the process of serializing a List object using Gson

I received data from the database using the method outlined below (a method from the spark-java framework): get("/data_on_page_load", "application/json", (Request request, Response response) -> { List<Post> list = Post.findAll(); // NEED TO S ...

How to implement custom unmarshalling in Go for nested JSON structures

I am working with a JSON object that represents a meal plan for a week. It includes a total of 21 entries, with each meal represented as an individual entry. { "name": "MealPlan 1508620645147", "items": [ { "day": 1, ...

How can we dynamically reference past elements in an array without using indices like "i-1", "i-2", and so on?

function play_tune(melody) { let played_notes = []; let durations = []; let positions = []; let wait_time = 0; let time_passed = 0; console.log("Melody initiation.") for (let key in melody) { played_notes.push(melody[key].note); dur ...

Convert an object with a property that stores a list of integers back into its original

I am attempting to deserialize a JSON object into my custom object using Newtonsoft.Json.JsonConvert. The JSON data I have is as follows: {"SelectedContentsID[]":"31807,32493,39517","pageSize":"20","SisconContentSubDialogEnum":"0","searchCriteria":"","page ...

Encountering a PHP error message indicating "Illegal string offset"

Currently, I am working on a PHP code that retrieves data from a dummy JSON API server. However, I am encountering the following errors: Warning: Illegal string offset 'employee_name' in C:\xampp\htdocs\jsonapi.php on line 19 name ...

Obtaining registration IDs for sending push notifications in curl PHP can be achieved by following these steps

Essentially... the scenario involves two working files: a curlphp script and an angular1 js file. In the js file, when an admin user clicks on 'send notification', it triggers an event to send a message by calling curl through a function. The f ...

Unexpected issue encountered for identifiers beginning with a numerical digit

Is it possible to select an element from a page with an id that begins with a number? $('#3|assets_main|ast_module|start-iso-date') Upon attempting to do so, the following error occurs: Uncaught Error: Syntax error, unrecognized expression: ...

"ModuleNotFound" error occurred when attempting to utilize Netlify lambda functions with external dependencies

https://i.stack.imgur.com/vVmky.jpg I'm currently exploring the capabilities of Netlify, specifically its lambda function feature for running a node function with dependencies. Following a tutorial from CSS-Tricks, my functions/submission-created.js ...

Retrieving data from a nested object with varying key names through ng-repeat

My JSON object contains various properties with unique names: var definitions = { foo: { bar: {abc: '123'}, baz: 'def' }, qux: { broom: 'mop', earth: { tree: 'leaf', water: 'fi ...