Application Packaging Standard

Last updated 18-Mar-2019

Loading Text and JSON

The require and define functions are used to load JavaScript modules and other files that the current code can require. To load a text content from a file, you should process it by a special plugin.

Loading Plain Text

To load a file content as a text, use the dojo/text! plugin as in the following example:

require([ ..., "dojo/text!./data/simpleText.txt",...],
   function(..., simpleText,...) {
      ...
});

In the above code, the text loaded from the simpleText.txt file is copied to the simpleText input parameter of the main callback function.

Loading JSON Object

A JSON definition can be loaded similar to a plain text, but to use the loaded contents as a JSON object it is necessary to process it preliminary by a JSON parser.

The aps/json! plugin processes a file content as a JSON code. The callback function will get a JavaScript JSON object that does not require additional parsing, for example:

define([ ..., "aps/json!./data/newvps.json",...],
   function(..., newVPS,...) {
      ...
      var vpsModel = getStateful({"data": newVPS});
      ...
});

In the above code, a stateful object is created from the newVPS JSON object directly without any preliminary conversion from text to JSON.