Retrieving data from Dojo's JsonRest and storing it as an object variable

After reading this post on Stack Overflow about how to Remove String from JSON, I am looking to populate a Dojo Selectbox with JSON Data. However, I am facing an issue where I need to modify the JSON Data before passing it to the dijit.form.select Box.

The data is retrieved using JsonRest. My question is, how can I load the JSON Data into a regular object variable? I attempted the code below but it did not yield the desired results.

var processStore = new JsonRest({
            target: "http://cnwin.ebusiness.local/activiti-rest/service/repository/process-definitions?startableByUser=kermit", 
            headers: {"Authorization": "Basic a2VybWl0Omtlcm1pdA=="}, 
            allowNoTrailingSlash: false
            });

var processes = processStore.query("",{});

My goal is simple - to retrieve JSON data from the JsonRest store and store it in a regular variable.

Thank you

Answer №1

The JsonRest store requires an array input, which means that if your data is not in the correct format, the store will not be able to retrieve it for you.

If you only need to read the data and not perform any other operations like updating or deleting, one way to achieve this is by making an AJAX request to fetch the data and manually populating a dojo/store/Memory store. Here's an example:

require([ "dojo/request/xhr", "dojo/store/Memory" ], function(xhr) {
    var url = "http://cnwin.ebusiness.local/activiti-rest/service/repository/process-definitions?startableByUser=kermit";

    xhr(url, {
        handleAs: json
    }).then(function(data) {
        if (data.data !== undefined) {
            var myStore = new Memory({
                data: data.data
            });
            // Manipulate "myStore" as needed
    });
});

If you want to explore the full functionality of the JsonRest store, you may need to customize it according to your requirements. By examining the code, you can see various AJAX requests in methods such as:

  • get()
  • put()
  • remove()
  • query()

You have the option to create your own store and extend these methods based on your specific needs.

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

Issue with cross-origin in Salesforce reply (Access-Control-Allow-Origin)

While attempting to retrieve records from Salesforce using external local files via JS, I encountered an issue. Although I can see a response in the network tab, the console displayed the following error message: "XMLHttpRequest cannot load . No 'A ...

When I attempt to open a file with a double click in my Electron app, Argv[1] gives me an unexpected value

When attempting to open a file by double-clicking, I encounter an issue while using electron-packager to build the application for the Mac App Store. Although I have set up the electron app to launch when a file is double-clicked, it appears that the file ...

Choosing Between Methods and Computed Properties in Vue.js

Can you explain the primary distinction between a method and a computed property in Vue.js? I'm finding it tricky to differentiate between the two as they appear quite similar. ...

Display the information by using the getJSON function and iterating through it with

I am working on a project where I receive JSON encoded data from a PHP script using $.getJSON. This data consists of 10 datasets that I want to display by fading out the old content, replacing it with the new one, and then fading in the updated information ...

How can I convert a string number with leading zeros into a string in a node.js environment?

When rendering a page, I pass the id as a string (e.g. 001, 002) but at the client side, I receive it as a number (e.g. 1, 2). res.render('leafletDemo',{id:userID,latitude:latitude,longitude:longitude}); Is there a way to keep the id as a str ...

Transmitting an HTML file along with JSON data and enabling the browser to refresh the JSON data without reloading the entire

I'm currently working on a project involving a browser-server program where the browser sends an http get request to ''. The server is expected to return both an HTML page and a JSON response. I attempted using res.render(), passing the JSON ...

Retrieving JSON data without keys using jansson

I need to extract values from a JSON file that lacks the key descriptor preceding the values, with the values being separated by a colon instead. Below is an example of the input format I am working with: {"out":[[0.2,15],[0.5,3.3],[0.1,46.8]],"in":[[0.6 ...

Using Jquery to trigger an alert in Bootstrap for an ASP.NET page has limited functionality and only works for the first instance

I need the save button to trigger without fail each time, no page refresh needed. Below is the code snippet I am using: Jquery Code In Admin.Master: <script> $(document).ready(function () { $("#successalert").hide(); $("#sucess").click(fun ...

Performing an AJAX call every half-hour using JavaScript

I am looking to implement an ajax request every 30 minutes using JavaScript. Specifically, for the user currently logged in, I aim to retrieve any notifications that have a start date matching the current time. These notifications are set by the user with ...

Make sure to select the checkbox using a protractor only if it hasn't been checked already

I am attempting to retrieve a list of checkboxes using CSS and only click on a checkbox if it is not already selected. I have successfully obtained the list, but I am encountering an issue when trying to validate whether or not the element is selected. Ca ...

The rule '@typescript-eslint/no-implicit-any' could not be located within Storybook JS's definition

Encountering an error after modifying the code generated by running Storybook.js. Following these instructions: https://gist.github.com/shilman/bc9cbedb2a7efb5ec6710337cbd20c0c Integrating StorybookJS into an existing project, only executed these command ...

The jQuery click and load function are failing to function as expected

Currently, I am facing an issue while trying to load text from a txt document into a div using the following code: $(document).ready(function(){ $('button').click(function(){ $('#contenthere').load('Load.txt'); ...

Return all HTML code from the Ajax element

I can't seem to pinpoint the issue with my code. When I make an ajax call using the code below: ajax.js: function ajaxObj(meth, url){ var x = new XMLHttpRequest(); x.open(meth, url, true); x.setRequestHeader("Content-type", "application/x-www_form-u ...

The PHP script encountered an issue with the HTTP response code while processing the AJAX contact form, specifically

Struggling to make this contact form function properly, I've tried to follow the example provided at . Unfortunately, all my efforts lead to a fatal error: "Call to undefined function http_response_code() in /hermes/bosoraweb183/b1669/ipg.tenkakletcom ...

Is it possible to selectively hide the remove icon for certain files within the antd Upload component?

Is there a way to specifically hide the remove button in the Antd Upload component for files that meet certain criteria? I am aware of the "showRemoveIcon" prop which disables the remove icon for every file, but is there a way to do this for only one fil ...

JavaScript's ability to call object properties at multiple levels allows for complex data

My approach involves using mongodb in conjunction with ajax calls for data retrieval. However, I have encountered an issue where the properties needed to generate HTML from JavaScript objects are sometimes missing. Consider this ajax call: $.ajax({ ...

Is there an issue with Three.js canvas.toDataURL() function in Chromium browsers?

After performing a recent system upgrade, I noticed some issues with Chromium. One of them was a delay in loading my Three.js r85 project, which was resolved after upgrading to Three.js r90. However, I encountered a new problem with toDataUrl() not workin ...

JavaScript Looping through multiple files for upload will return the last file in the series

I'm currently working on implementing a multiple file upload feature using JavaScript. Within my HTML, I have the following input: <input type="file" (change)="fileChange($event,showFileNames)" multiple /> When the onChange event is triggere ...

Issue with Three.js GLTF loader peculiar behavior while attempting to incorporate three-dimensional text

I had an idea to import a prebuilt gltf scene created in Blender, then add some 3D text using the ttf loader and manipulate it. Each loader worked perfectly when used separately, but strange things started happening when I combined them into a single scrip ...

Error: The function `push` cannot be used on the variable `result` (TypeError)

Here is a snippet from my react component const mockFetch = () => Promise.resolve({ json: () => new Promise((resolve) => setTimeout(() => resolve({ student1: { studentName: 'student1' }, student2: { studen ...