adirocks27
adirocks27

Reputation: 31

Push Data to JSONModel

I have a model with following data:

oData_main = {EmployeeName: "abc", EmployeeID:"123"};

I want to add data from another model to my model, so that resultant model data will look like this.

oData_phone:{home:"789",office:"567"} `//this is a temporary variable.`

oData_main= {EmployeeName: "abc", EmployeeID:"123", phone:{home:"789",office:"567"}};

I'm trying to do this in SAP UI5 application.

Upvotes: 0

Views: 4771

Answers (2)

Ashish Patil
Ashish Patil

Reputation: 1742

setData method of JSONModel has parameter to merge new data with existing one.

Below is the code for it

var oModel = new sap.ui.model.json.JSONModel({
    EmployeeName: "abc",
    EmployeeID: "123"
});
var oNewData = {
    phone: {
        home: "789",
        office: "567"
    }
};
oModel.setData(oNewData, true);

Upvotes: 0

hirse
hirse

Reputation: 2412

You can use the JSONModel's setProperty method:

var oModel = new sap.ui.model.json.JSONModel({
    EmployeeName: "abc",
    EmployeeID: "123"
});
oModel.setProperty("/phone", {
    home: "789",
    office: "567"
});

Upvotes: 1

Related Questions