SAP UI5 - 创建值为“0”的模型

时间:2016-04-04 15:20:22

标签: sap sapui5

我正在for循环中创建模型实例(0 - 6)......

除DayOfWeek = 0时,一切正常,在这种情况下,默认值输入到模型中,而不是正确的值0。

for (var i = 0; i < 7 ; i++) {
  var oEntry = {};
  oEntry.DayOfWeek = i;

  oModel.create("/CalendarSet", oEntry, {
    success : success,
    error : error
  });

  oModel.submitChanges(success, error);
}

1 个答案:

答案 0 :(得分:0)

var oModel = new sap.ui.model.json.JSONModel();
var oModelOData = new sap.ui.model.odata.ODataModel();

for (var i = 0; i < 7 ; i++) {
    oEntry.DayOfWeek = i;
    oModel.setProperty("/CalendarSet", oEntry);
    oModelOData.setProperty("/CalendarSet", oEntry);
});

Btw. to use submit changes you need an OData Model V2, simply change sap.ui.model.odata.ODataModel to sap.ui.model.odata.v2.ODataModel, everything else stays the same.