我正在嘗試構建一個簡單的 SAPUI5 應用程序,它基本上列出了一個填充了員工數據(ID、姓名、地址)的表。 但是,我無法添加新員工,因為我總是遇到同樣的錯誤:Uncaught TypeError: oModel.create is not a function at constructor.Save (EmpDetails.controller.js?eval:87)你能幫我解決這個問題嗎?我不明白為什么 create 函數不起作用,因為它已連接到模型并且應該可以正常工作(就像在初始化時填充表的 GET 方法一樣)。這是我的控制器代碼:sap.ui.controller("zemployee_crud.EmpDetails", { onInit: function() { var sServiceUrl = "proxy/http/<server>:<port>/sap/opu/odata/sap/ZEMPLOYEE_SRV"; var oModel = new sap.ui.model.odata.ODataModel(sServiceUrl, true); var oJsonModel = new sap.ui.model.json.JSONModel(); oModel.read("/EmployeeSet",null,null,true,function(oData,response){ oJsonModel.setData(oData); }); sap.ui.getCore().setModel(oJsonModel); }, Save: function() { var oId = sap.ui.getCore().byId("Id").getValue(); var oName = sap.ui.getCore().byId("Name").getValue(); var oAddress = sap.ui.getCore().byId("Address").getValue(); var oEntry = {}; oEntry.Empid = oId; oEntry.Empname = oName; oEntry.Empadd = oAddress; var oModel = sap.ui.getCore().getModel(); oModel.create("/EmployeeSet", oEntry, null, function (response) { // success message // table reload }, function (Error) { //show error }); }});
SAPUI5 - oModel.create 不是函數
泛舟湖上清波郎朗
2022-07-21 09:50:10