我正在尝试构建一个简单的 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
});
}
});
摇曳的蔷薇
相关分类