gpt4 book ai didi

javascript - 根据用户输入 ,"Uncaught TypeError: Cannot read property ' 调用 get 实体时读取未定义的

转载 作者:行者123 更新时间:2023-11-30 14:22:32 33 4
gpt4 key购买 nike

我试图调用 oData 来读取基于 UI5 屏幕上用户输入的值。我在 UI5 屏幕上输入 Material 单号和会计年度。但是当它执行语法 this.getView().getModel("OData").create("/UserInputSet", oViewModel, 时,它说

Uncaught TypeError: Cannot read property 'read' of undefined.

Controller :

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 文件中定义,绑定(bind)到 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

关于javascript - 根据用户输入 ,"Uncaught TypeError: Cannot read property ' 调用 get 实体时读取未定义的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52509100/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com