简体   繁体   English

当基于用户输入调用get实体时,“ Uncaught TypeError:无法读取未定义的属性'read'

[英]when calling the get entity based on user input ,"Uncaught TypeError: Cannot read property 'read' of undefined

I was trying to call the oData to read the values based on user input on UI5 screen. 我试图调用oData以根据UI5屏幕上的用户输入读取值。 I am entering Material doc no and fiscal year on UI5 screen. 我在UI5屏幕上输入物料凭证编号和会计年度。 But when it execute the syntax this.getView().getModel("OData").create("/UserInputSet", oViewModel, , it says 但是,当执行语法this.getView().getModel("OData").create("/UserInputSet", oViewModel, ,它说

Uncaught TypeError: Cannot read property 'read' of undefined. Uncaught TypeError:无法读取未定义的属性“ read”。

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 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>

By calling this.getView().getModel("OData") you're trying to get the instance of a model called "OData". 通过调用this.getView().getModel("OData")您试图获取名为“ OData”的模型的实例。 If that's returning undefined it means this model is not defined. 如果返回undefined则表示该模型未定义。

Usually OData models are defined in the manifest.json file, bound to a dataSource . 通常,OData模型是在manifest.json文件中定义的,绑定到dataSource Like this: 像这样:

{
    "sap.app": {
        "dataSources": {
            "mainService": {
                "uri": "/relative/uri/of/the/service",
                "type": "OData"
            }
        }
    },
    "sap.ui5": {
        "models": {
            "": {
                "dataSource": "mainService"
            }
        }
    }
}

The "" means it's the default model, and it can be accessed without specifying a name. ""表示它是默认型号,无需指定名称即可访问。

Since normally the default OData model is defined without a name ( "" ) I suggest you try to call it like this: 由于通常默认的OData模型是在没有名称( "" )的情况下定义的,因此建议您尝试这样调用它:

this.getView().getModel()

If that doesn't work, revise your manifest.json file and include a model definition. 如果这不起作用,请修改manifest.json文件并包含模型定义。

You can check the docs for the manifest.json file here: https://sapui5.hana.ondemand.com/#/topic/be0cf40f61184b358b5faedaec98b2da.html 您可以在此处检查manifest.json文件的文档: https : //sapui5.hana.ondemand.com/#/topic/be0cf40f61184b358b5faedaec98b2da.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未捕获的类型错误:调用函数时无法读取未定义的属性“then” - Uncaught TypeError: Cannot read property 'then' of undefined when calling a function 未捕获的类型错误:无法读取未定义的属性“get” - Uncaught TypeError: Cannot read property 'get' of undefined 未捕获的TypeError:无法读取未定义的属性“未定义” - Uncaught TypeError: Cannot read property 'undefined' of undefined 调用firebase.auth()。onAuthStateChanged()时出现“ Uncaught TypeError:无法读取未定义的属性&#39;resolve&#39;” - “Uncaught TypeError: Cannot read property 'resolve' of undefined” when calling firebase.auth().onAuthStateChanged() 未捕获的类型错误:无法读取 VueJs 中未定义的属性“get” - Uncaught TypeError: Cannot read property 'get' of undefined in VueJs 解析-未捕获的TypeError:无法读取未定义的属性“ get” - Parse - Uncaught TypeError: Cannot read property 'get' of undefined 未捕获的类型错误:无法读取未定义错误的属性“get” - Uncaught TypeError: Cannot read property 'get' of undefined error 捕获TypeError:尽管有条件,但无法读取未定义的属性“ get” - Getting Uncaught TypeError: Cannot read property 'get' of undefined in spite of the conditionals 解析未捕获的TypeError:无法读取未定义的属性“ get” - Parse Uncaught TypeError: Cannot read property 'get' of undefined 为什么我得到 Uncaught TypeError: Cannot read property &#39;sequence&#39; of undefined - why I get Uncaught TypeError: Cannot read property 'sequence' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM