TreePanel without a designated URL in the ExtJS store

Model:

Ext.define('Item', {
    extend: 'Ext.data.Model',
    fields: [
        {name: 'item',     type: 'string'},
//      {name: 'active',     type: 'string'},
        {name: 'quantity', type: 'string'}
    ]
});

Inventory:

var inventoryStore = Ext.create('Ext.data.TreeStore', {
        model: 'Item',
        proxy: {
            type: 'ajax',
            url: 'inventory.json'
        },
        folderSort: true
    });

TreePanel:

var treePanel = Ext.create('Ext.tree.Panel', {
        title: 'Warehouse Inventory',
        width: 500,
        height: 300,
        renderTo: Ext.getBody(),
        collapsible: true,
        useArrows: true,
        rootVisible: false,
        store: inventoryStore,
        multiSelect: true,
        singleExpand: true,
        //the 'columns' property is now 'headers'
        columns: [{
            xtype: 'treecolumn',
            text: 'Item Name',
            flex: 2,
            sortable: true,
            dataIndex: 'item'
        },{
            text: 'Quantity',
            flex: 1,
            dataIndex: 'quantity',
            sortable: true
        }]
    });
    this.add(treePanel);
    this.doLayout();

Issue: I can load the tree panel using data from an external JSON file. However, I want to load it with a decoded JSON object received from the server. Here's an example of the desired structure:

Data Object:

{"text":".",
"children":[
{"item":"Apples","quantity":"15000","expanded":"true","children":[
      {"item":"Green Apples","quantity":"7000","expanded":"true","children":[
         {"item":"Granny Smith","quantity":"3500","leaf":"true"},
         {"item":"Golden Delicious","quantity":"3500","leaf":"true"}
      ]
   },
   {"item":"Oranges","quantity":"8000","expanded":"true","children":[
      {"item":"Navel Oranges","quantity":"3000","leaf":"true"},
      {"item":"Blood Oranges","quantity":"5000","leaf":"true"}
   ]}]
},
   {"item":"Bananas","quantity":"40000","expanded":"true","children":[
      {"item":"Cavendish Bananas","quantity":"15000","leaf":"true"},
      {"item":"Plantain Bananas","quantity":"25000","leaf":"true"}
   ]
}]}

However, using this custom data object causes the texts to not display properly in the tree panel.

Answer №1

Implement a memory-based proxy along with the root configuration:

var dataStore = Ext.create('Ext.data.TreeStore', {
    model: 'Product',
    proxy: {
        type: 'memory'
    },
    root: sampleData,
    folderSort: true
});

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 best way to execute a method in a component for each iteration in an *ngFor loop in Angular 2

Is there a way to call a method for each iteration of *ngFor and pass the iterated variable as a parameter? For example: <li *ngFor="let element of componentModel | keys">{{element.key}}--{{element.value}}</li> Then, in the component, I have ...

Extract JSON-encoded attributes from the body of the request

When sending a list of dictionaries as the value of a dictionary with requests.post, I am json encoding an attribute in the POST data request. However, I am struggling to read it back. Upon receiving the request at my endpoint, the body appears like this: ...

What's the best way to insert a new object into an array every time I execute a function?

I want to implement a system that creates an object and adds it to an array whenever new data is entered and the 'add' button is pressed. However, I'm unsure of the correct way to add a new object to an array. Also, for some reason, my code ...

Unable to insert the string into the INSERT query

My input is in JSON format $page = file_get_contents('http://example.com/products.html'); $items = json_decode($page, true); When I echo $page, it displays something like this: { "productlist":[ { "id":"1", "cat":"milk", "prod_name":"happy mil ...

Control the prompt with the Puppeteer typing function

Hello, I am currently attempting to log into a system that looks like the following: The input fields are labeled as username and password, with buttons labeled as login and cancel. I am trying to input data into these fields and click on the login ...

How to apply an active class using Javascript and jQuery

I've been trying to figure out how to apply the active class to my unordered list using jQuery. Despite attempting various solutions found on Stackoverflow, nothing seems to be working. My goal is to have the text color change to red when the active c ...

Does anyone have a solution for resetting the ID numbers in a flatlist after removing an item from it?

As the title suggests, I am facing an issue with the following scenario: { id: '1', name: 'one' }, { id: '2', name: 'two' }, { id: '3', name: 'three' }, { id: '4', name: &apo ...

Tips for embedding the <img> element inside the <a> element

I'm attempting to place an image within a hyperlink tag. Current code: <div class="Sample"> <a href="http://www.Sample.com"> <img src="http://www.Sample.com/Sloth.jpg"> </a> </div> I wish to add <img class= ...

When using the parseFloat function with a regular expression input, it results

My goal is to adjust float values within a string by a specific amount. Here is my current approach: var string = '<path d="M219.6,-71.4C249,19.1,212.7,130.9,135.7,186.8C58.8,242.7,-58.8,242.7,-135.7,186.8C-212.7,130.9,-249,19.1,-219.6,-71.4C-19 ...

Tips for creating a conditional CSS pseudo-element using styled-components

I am attempting to create a styled-component with conditional pseudo-elements, but I am having trouble getting it to work properly. Could someone confirm if the syntax I am using is correct? For the context: I want to achieve a scenario where if isSelecte ...

Dealing with the main directory/path in Express and Node JS

I've been working on my site using Express and Node JS, and I'm attempting to handle users' requests for 'www.mysite.com/' or 'www.mysite.com' by redirecting them to 'www.mysite.com/dashboard'. Is there a way to ...

modify the designation of a particular element's group

My goal is to create a webpage that features multiple tables with data. To prevent the page from getting too long, I want users to have the ability to collapse these tables by clicking on the header. I intend to use a + icon to signify expandable content a ...

Enhancing leaflet popup functionality by incorporating ng-click into the onEachFeature function

After creating a map and connecting it with my geojson api, I encountered an issue when trying to link each marker popup with ng-click. Simply adding HTML like this did not work as expected: layer.bindPopup("<button ng-click='()'>+feature. ...

What is the best way to transfer specific information from one document to another?

Feeling a bit lost here, not sure where to begin my search... Here is a snippet of the data stored in a txt file: System.Threading.Tasks.Task`1[System.Threading.Tasks.VoidTaskResult] { "_id" : 3000020, "Payload" : { "category_id" : "/1/1/", "Data" : { "ca ...

Switch the display based on user interaction in Angular2

Looking for assistance with changing the view in my Angular2 template: <td *ngIf="hour === first">{{obj[0].from}}</td> <td *ngIf="hour === second">{{obj[1].from}}</td> <td *ngIf="hour === third">{{obj[2].from}}</td> Th ...

What is the best way to display the success message within the if statement once the values are retrieved from an Ajax request?

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.net.*" %> <%@ page import="java.io.*" %> <%@ page import="java.util.*" %> <%@ page import="java.sql.*" %> <!DO ...

Tips for locating the :before element's position with Javascript

I am currently working on an animation where I need to change the color of an element in the center once a small circle touches it. Despite trying to use the position() method, it does not work as intended because I am using a :before for animating the div ...

Converting a C# two-dimensional array into JavaScript formatting

Is there a more streamlined method for converting a two-dimensional array in C# like [[1, 2, 3],[4, 5, 6]] into a string representation "[[1, 2, 3],[4, 5, 6]]" without manually iterating through each value and formatting it? I want to pass the array as an ...

Exploring RPG YAJL's ability to parse nested arrays

I am new to RPG and feeling a bit overwhelmed with this task. I have an array called "data" that contains information which I can parse easily. However, within the "data" array, there is another array called "cargoLoaded" that holds a single item named "ca ...

Revamping the hyperlinks in my collapsible menu extension

Is there a way to modify the links in this accordion drop menu so that they lead to external HTML pages instead of specific areas on the same page? I've tried various methods but can't seem to achieve it without affecting the styles. Currently, i ...