![](/img/trans.png)
[英]Uncaught TypeError: Cannot read property 'then' of undefined when calling a function
[英]when calling the get entity based on user input ,"Uncaught TypeError: Cannot read property 'read' of undefined
我試圖調用oData以根據UI5屏幕上的用戶輸入讀取值。 我在UI5屏幕上輸入物料憑證編號和會計年度。 但是,當執行語法this.getView().getModel("OData").create("/UserInputSet", oViewModel,
,它說
Uncaught TypeError:無法讀取未定義的屬性“ read”。
控制器:
onNext : function(){
debugger;
var oViewModel = {};
oViewModel.Mblnr = this.getView().byId("idMd").getValue();
oViewModel.Mjahr = this.getView().byId("idFy").getValue();
if (oViewModel.Mblnr === "") {
// alert('Please Enter the material Doc No');
var msg = ("Please Enter the material Doc No.");
MessageToast.show(msg);
} else
if (oViewModel.Mjahr === "") {
msg = ("Please Enter the fiscal year");
MessageToast.show(msg);
} else {
this.getView().getModel("OData").read("/UserInputSet", oViewModel, {success: function(OData, response) {
MessageToast.show("Material No exist in table");
},error: function(OData, response) { MessageToast.show("Error");
}
XML
<Page id="idFirst" title="Update Picking Completion App ">
<headerContent>
<Button press="onNext" icon="sap-icon://feeder-arrow" iconFirst="false" text="Execute" tooltip="Execute" type="Accept"
class="customCss_ForButton"/>
</headerContent>
<f:SimpleForm id="idSimple" title="User Input screen" editable="true" layout="ResponsiveGridLayout" labelSpanXL="4" labelSpanL="4"
labelSpanM="4" labelSpanS="4" adjustLabelSpan="false" emptySpanXL="4" emptySpanL="4" emptySpanM="4" emptySpanS="0" columnsXL="1"
columnsL="1" columnsM="1" singleContainerFullSize="true">
<f:content >
<Label text="Material Doc No"/>
<Input id="idMd" placeholder="Enter material doc ..." width="auto" maxLength="10" required="true">
<layoutData>
<l:GridData span="XL1 L2 M2 S4"/>
</layoutData>
</Input>
<Label text="Fiscal Year"/>
<Input id="idFy" type="Text" placeholder="Enter fiscal year ..." width="auto" maxLength="4" required="true">
<layoutData>
<l:GridData span="XL1 L2 M2 S4"/>
</layoutData>
</Input>
<Button text="Execute" width="150px" icon="sap-icon://feeder-arrow" iconFirst="false" press="onNext" type="Accept"
class="customCss_ForButton"/>
</f:content>
</f:SimpleForm>
</Page>
通過調用this.getView().getModel("OData")
您試圖獲取名為“ OData”的模型的實例。 如果返回undefined
則表示該模型未定義。
通常,OData模型是在manifest.json
文件中定義的,綁定到dataSource
。 像這樣:
{
"sap.app": {
"dataSources": {
"mainService": {
"uri": "/relative/uri/of/the/service",
"type": "OData"
}
}
},
"sap.ui5": {
"models": {
"": {
"dataSource": "mainService"
}
}
}
}
""
表示它是默認型號,無需指定名稱即可訪問。
由於通常默認的OData模型是在沒有名稱( ""
)的情況下定義的,因此建議您嘗試這樣調用它:
this.getView().getModel()
如果這不起作用,請修改manifest.json文件並包含模型定義。
您可以在此處檢查manifest.json文件的文檔: https : //sapui5.hana.ondemand.com/#/topic/be0cf40f61184b358b5faedaec98b2da.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.