The JSON model can be used to bind controls to JavaScript object data, which is usually
serialized in the JSON format. The JSON model is a client-side model and, therefore,
intended for small datasets, which are completely available on the client. The JSON model
does not support mechanisms for server-based paging or loading of deltas. It
supports, however, two-way binding.
Procedure
- To create a JSON model instance, insert the following code:
var oModel = new sap.ui.model.json.JSONModel();
- After the instance has been created, there are different options to get the
data into the model.
- The easiest option is to set data by using the setData
method:
oModel.setData({
firstName: "Peter",
lastName: "Pan"
});
Note The correct JSON notation uses
double quotes for the keys and string values.
- Usually, you do not define your data inline in the application but load
it from a server-side service using an XHR request. The JSON model, however,
also has a loadData method, which loads the JSON data from
the specified URL asynchronously and applies it to the model:
oModel.loadData("data.json");