0
我的模型使用OData的模型
var oModel = new sap.ui.model.odata.ODataModel("../services/myexp.xsodata", false);
sap.ui.getCore().setModel(oModel,'data');
現在我想新的記錄添加到這個模型中添加新的記錄。簡單的代碼 -
openUserCreateDialog: function(){
var oUserCreateDialog = new sap.ui.commons.Dialog();
var oSimpleForm1 = new sap.ui.layout.form.SimpleForm({
maxContainerCols: 2,
content:[
new sap.ui.core.Title({text:"Create"}),
new sap.ui.commons.Label({text:"User"}),
new sap.ui.commons.TextField({value:""}),
new sap.ui.commons.Label({text:"Date"}),
new sap.ui.commons.TextField({value:""}),
new sap.ui.commons.Label({text:"Description"}),
new sap.ui.commons.TextField({value:""})
]
});
oUserCreateDialog.addContent(oSimpleForm1);
oUserCreateDialog.addButton(
new sap.ui.commons.Button({
text: "Submit",
press: function() {
var content = oSimpleForm1.getContent();
var oEntry = {};
oEntry.User = content[2].getValue();
oEntry.Date = content[4].getValue();
oEntry.Description = content[6].getValue();
sap.ui.getCore().getModel().create('data>/user', oEntry, null, function(){
oUserCreateDialog.close();
sap.ui.getCore().getModel().refresh();
},function(){
oUserCreateDialog.close();
alert("Create failed");
}
);
}
})
);
oUserCreateDialog.open();
},
當我提交表單,它拋出一個錯誤原樣
Uncaught TypeError: sap.ui.getCore(...).getModel(...).create is not a function
什麼是錯我的代碼。請幫忙。謝謝
謝謝...它的工作 –