如何在SAPUI5中使用oData创建批处理,但我每次都能创建单个记录

时间:2017-11-25 21:40:36

标签: odata sapui5

我无法发送批量记录。但我每次都能添加单个实体。我在提交时使用了以下功能。 //每次创建单个条目。 onSubmitChanges:function(){

        var oSelectedVal = this.getView().byId("plmSelect"),
            oSelectedVal = oSelectedVal.getSelectedItem().getKey(),
            oModel = this.getView().getModel(),
            oEntry = {};
        oEntry.MyKeyField1 = oSelectedVal;
        oEntry.MyEntry1  = globalVariable1; // global variable declared to get values
        oEntry.MyEntry2  = globalVariable2;
        oEntry.MyEntry3  = globalVariable3;
        oEntry.MyEntry4  = globalVariable4;

        if (oEntry.MyKeyField1 !== "" && oEntry.MyEntry1 !== "" && oEntry.MyEntry2 !== "") {
            var oContext = oModel.createEntry('/MyEntitySet', {
                properties: oEntry,
                success: function() {
                    MessageToast.show("Create successfuly");
                    // not able to delete/remove after created successfully used the following

                    //oModel.setBindingContext(oContext);
                    //oModel.resetChanges();
                    //aModel.destroyBindingContext();

                    /*oModel.updateBindings({
                        bForceUpdate: true
                    });*/
                    //  oModel.refresh();
                    //oModel.deleteCreatedEntry();
                },
                error: function() {
                    MessageToast.show("Create failed");
                }
            });
            oModel.submitChanges();

            //oModel.refresh();

        } else {
            MessageToast.show("Store Area and Store Description are madatory.");
        }
        this.onUpdateFinished();
    },

1 个答案:

答案 0 :(得分:-2)

不允许批量处理。如果你想发表一张桌子,你必须使用深层实体。