将数据推送到JSONModel

时间:2016-05-11 09:20:17

标签: javascript json sapui5

我有一个包含以下数据的模型:

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

我想将另一个模型的数据添加到我的模型中,因此结果模型数据将如下所示。

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

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

我试图在SAP UI5应用程序中执行此操作。

2 个答案:

答案 0 :(得分:1)

您可以使用JSONModel' setProperty方法:

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

答案 1 :(得分:0)

JSONModel的{​​{1}}方法具有将新数据与现有数据合并的参数。

以下是它的代码

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