Introduction
This tutorial shows you how to use a local JSON document in your Oracle JavaScript Extension Toolkit (Oracle JET) virtual DOM app.
Oracle JET is a development toolkit that provides a number of data provider classes to manage data from various sources. In this tutorial, you’ll populate an instance of the MutableArrayDataProvider class with the data you read from a JSON file, and then bind the MutableArrayDataProvider instance to Oracle JET custom HTML elements.
Objectives
In this tutorial, you will learn how to read data from a JSON document into a data provider, add an Oracle JET List View component, and data bind the Oracle JET List View component to the JSON data objects.
Prerequisites
- A development environment set up to create Oracle JET virtual DOM apps that includes an installation of Node.js
- Completion of the previous tutorial in this learning path, Add Components to an Oracle JET Virtual DOM App
- The store_data.json downloaded to the
JET-Virtual-DOM-app/src/components/directory
Task 1: Download the JSON Document and Examine the Data
-
Download the
store_data.jsonfile to theJET-Virtual-DOM-app/src/componentsdirectory. -
Open the
store_data.jsonfile in your web browser and view the data structure. Thestore_data.jsonfile contains a list of activity objects and their properties. Each activity includes an array of items with their own properties.
Task 2: Populate a Data Provider in Your Virtual DOM App
Push data from the JSON file into an instance of an Oracle JET MutableArrayDataProvider class.
-
Navigate to the
JET-Virtual-DOM-app/src/components/contentdirectory and open theindex.tsxfile in an editor. -
Import the data from the
store_data.jsonfile so that it is available in your virtual DOM app.import { h, ComponentProps } from "preact"; import { useState, useCallback } from "preact/hooks"; import "ojs/ojlabel"; import "ojs/ojselectsingle"; import { ojSelectSingle } from "ojs/ojselectsingle"; import MutableArrayDataProvider = require("ojs/ojmutablearraydataprovider"); import "ojs/ojchart"; import { ojChart } from "ojs/ojchart"; import * as storeData from "text!../store_data.json";The
MutableArrayDataProvidermodule that you use to hold the JSON data was imported in the previous tutorial. -
Before the
Content ()function, define theActivitytype alias, which includes theidfield of typenumberand thenamefield of typestring.... type Activity = { id: number; name: string; } export function Content() { . . . -
Also before the
Content ()function, create an instance ofMutableArrayDataProvider(activityDataProvider) and use theJSON.parsemethod to read in the JSON data.... type Activity = { id: number; name: string; } const parsedData = typeof storeData === "string" ? JSON.parse(storeData) : storeData; const activityDataProvider = new MutableArrayDataProvider<Activity["id"], Activity>( parsedData, { keyAttributes: "id" } ); export function Content() { . . . -
Import the type definition and the module for the Oracle JET List View component as well as the module for the List Item Layout component.
. . . import MutableArrayDataProvider = require("ojs/ojmutablearraydataprovider"); import "ojs/ojchart"; import { ojChart } from "ojs/ojchart"; import * as storeData from "text!../store_data.json"; import "ojs/ojlistview"; import { ojListView } from "ojs/ojlistview"; import "ojs/ojlistitemlayout"; -
Save the
index.tsxfile.Your
index.tsxfile should look similar to final-data-bind-index-tsx.txt.
Task 3: Bind Data to the List View Component
The oj-list-view element is an Oracle JET custom HTML element with interactive features that is an enhanced version of an HTML list. You provide the data to the list by binding the activityDataProvider instance to the data attribute of the List View component.
-
In the open
index.tsxfile, add adivelement with anidattribute value ofactivitiesContainerabove theitemDetailsContainerdivelement that contains the Oracle JET Select Single and Chart components.<div class="oj-web-applayout-max-width oj-web-applayout-content"> <h1>Product Information</h1> <div id="activitiesContainer"> </div> <div id="itemDetailsContainer"> <oj-label for="basicSelect">Select Chart:</oj-label> <oj-select-single . . . -
Within the
activitiesContainerdivelement, add anoj-list-viewelement with adataattribute that references the instance ofMutableArrayDataProviderwe created previously (activityDataProvider).<div class="oj-web-applayout-max-width oj-web-applayout-content"> <h1>Product Information</h1> <div id="activitiesContainer"> <oj-list-view id="activitiesList" aria-labelledby="activitiesHeader" data= {activityDataProvider} gridlines={gridlinesItemVisible}> </oj-list-view> </div> <div id="itemDetailsContainer"> <oj-label for="basicSelect">Select Chart:</oj-label> <oj-select-single . . .We specify the
aria-labelledbyattribute as an accessibility best practice, and we also specify thegridlinesItemVisiblevalue for thegridlinesattribute to display a grid line between items in the list. We'll perform an additional step to access thegridlinesattribute of the List View component. -
Within the
oj-list-viewelement you created, add an HTMLtemplateelement withslotandrenderattributes to render each item in the list.return ( <div class="oj-web-applayout-max-width oj-web-applayout-content"> <h1>Product Information</h1> <div id="activitiesContainer"> <oj-list-view id="activitiesList" aria-labelledby="activitiesHeader" data= {activityDataProvider} gridlines={gridlinesItemVisible}> <template slot="itemTemplate" render={renderListItem}></template> </oj-list-view> </div> -
Within the
activitiesContainerdivinside thereturnstatement, add an HTMLh3element to supply a header for the list of activities.<div id="activitiesContainer"> <h3 id="activitiesHeader">Activities</h3> <oj-list-view id="activitiesList" aria-labelledby="activitiesHeader" data={activityDataProvider} gridlines={gridlinesItemVisible} > <template slot="itemTemplate" render={renderListItem}></template> </oj-list-view> </div> -
In the
itemDetailsContainerdiv, add anh3element to supply a header for the chart.<div id="itemDetailsContainer"> <h3>Item Details</h3> <oj-label for="basicSelect">Select Chart:</oj-label> <oj-select-single -
Before the
returnstatement in theContent()function, add arenderListItemfunction that returns a list of activity names to render in the List View component.. . . export function Content() { . . . const renderListItem = (item: ojListView.ItemTemplateContext<Activity["id"], Activity> ) => { return ( <li> <oj-list-item-layout> <div class="oj-typography-body-md"> {item.data.name} </div> </oj-list-item-layout> </li> ); } ; return ( . . . <oj-list-view . . . -
Before the
Content()function, declare aListViewPropstype and use it to create a variable (gridlinesVisible) with a value ofvisible.. . . type ListViewProps = ComponentProps<"oj-list-view">; const gridlinesItemVisible: ListViewProps["gridlines"] = { item: "visible" }; export function Content() { const renderListItem = . . . -
Save the
index.tsxfile.Your
index.tsxfile should look similar to index.tsx.txt.
Task 4: Run the Virtual DOM App
-
In the terminal window, change to the
JET-Virtual-DOM-appdirectory and run the app.npx ojet serveYour browser displays the list of activities visible in your virtual DOM app.

-
Close the browser window or tab that displays your running virtual DOM app.
-
In the terminal window, press Ctrl+C, and, if prompted, enter
yto exit the Oracle JET tooling batch job. -
Leave the terminal window open for your next tutorial.
Next Step
Proceed to the next tutorial in this module.
This tutorial is part of the module Your First Oracle JET Virtual DOM App.
- Create an Oracle JET Virtual DOM App by Using a Starter Template
- Add Components to an Oracle JET Virtual DOM App
- Data Bind a Component in an Oracle JET Virtual DOM App
- Debug an Oracle JET Virtual DOM App
- Add Unit Tests to an Oracle JET Virtual DOM App
- Prepare to Deploy an Oracle JET Virtual DOM App
You can return to the virtual DOM learning path’s main page to access all the modules on building virtual DOM apps.
More Learning Resources
Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel.
For product documentation, visit Oracle Help Center.
Data bind a component in an Oracle JET virtual DOM app
F61085-05
Copyright © 2024,2026 Oracle and/or its affiliates.