我正在尝试通过OData服务连接到后端ABAP系统,但我收到错误,如屏幕截图所示。
library-preload.js:522 Uncaught TypeError:无法读取属性' read'未定义的(...)
这里是各种文件的代码:
新app.json:
{
"path": "/DB7",
"target": {
"type": "destination",
"name": "DB7"
},
"description": "DB7"
}
Component.js
init: function() { var oModel = new sap.ui.model.odata.v2.ODataModel(this.getMetadata().getConfig().serviceUrl);
this.setModel(oModel,"data");
}
的manifest.json
{
"_version": "1.1.0",
"sap.app": {
"_version": "1.1.0",
"id": "com.abc.cup",
"type": "application",
"i18n": "i18n/i18n.properties",
"applicationVersion": {
"version": "1.0.0"
},
"title": "{{appTitle}}",
"description": "{{appDescription}}",
"sourceTemplate": {
"id": "ui5template.basicSAPUI5ApplicationProject",
"version": "1.32.0"
},
"dataSources": {
"invoiceRemote": {
"uri": "/destinations/DB7/sap/opu/odata/ATSH/UI5_DISPLAY_SRV/",
"type": "OData",
"settings": {
"odataVersion": "2.0"
}
}
}
},
"sap.ui": {
"_version": "1.1.0",
"technology": "UI5",
"icons": {
"icon": "",
"favIcon": "favicon.ico",
"phone": "",
"phone@2": "",
"tablet": "",
"tablet@2": ""
},
"deviceTypes": {
"desktop": true,
"tablet": true,
"phone": true
},
"supportedThemes": ["sap_hcb", "sap_bluecrystal"]
},
"sap.ui5": {
"_version": "1.1.0",
"rootView": {
"viewName": "com.abc.cop.view.View1",
"type": "XML"
},
"dependencies": {
"minUI5Version": "1.30.0",
"libs": {
"sap.ui.core": {},
"sap.m": {},
"sap.ui.layout": {}
}
},
"contentDensities": {
"compact": true,
"cozy": true
},
"models": {
"":{
"dataSource": "invoiceRemote",
"settings":{}
},
"i18n": {
"type": "sap.ui.model.resource.ResourceModel",
"settings": {
"bundleName": "com.abc.cop.i18n.i18n"
}
}
},
"resources": {
"css": [{
"uri": "css/style.css"
}]
},
"routing": {
"config": {
"routerClass": "sap.m.routing.Router",
"viewPath": "com.abc.cop.view",
"controlId": "appId",
"controlAggregation": "pages",
"transition": "fade"
},
"routes": [{
"name": "main",
"pattern": "",
"target": ["initialScreen"]
}, {
"name": "moreDetails",
"pattern": "moreDetails",
"target": ["moreDetails"],
"greedy": true
}
],
"targets": {
"main": {
"viewType": "XML",
"transition": "slide",
"viewName": "View1",
"viewId": "view1",
"viewLevel": 1
},
"moreDetails": {
"viewType": "XML",
"transition": "fade",
"viewName": "View2",
"viewId": "view2",
"clearAggregation": true,
"viewLevel": 2,
"controlId": "appId"
},
"initialScreen": {
"viewType": "XML",
"transition": "fade",
"clearAggregation": true,
"viewName": "View3",
"viewId": "view3"
}
}
}
}
}
Controller.js
onBeforeRendering: function() {
var oModell = new sap.ui.model.odata.ODataModel(
"https://webidetesting3386376-p1942296689trial.dispatcher.hanatrial.ondemand.com/destinations/DB7/sap/opu/odata/ATSH/UI5_DISPLAY_SRV/"
);
//var oJSONModel = new sap.ui.model.json.JSONModel();
oModell.read("SY_INFOSet(Customer='ABC',Sysid='DB7')", null, null, true, function(oData, oResponse) {
alert("Read successful: " + JSON.stringify(oData));
this.getView().setModel(oModell, "jsonData");
//var oModel22 = new sap.ui.model.json.JSONModel(oData);
//sap.ui.getCore().setModel(oModel22, "jsonData");
}, function() {
alert("Read failed");
});
},
view.xml用
<ObjectHeader class="HeaderObjectwidth" id="objectHeader" title="{i18n>systemId} - {SYS_INFOSet/Sysid}" number="{i18n>numUsers} {SYS_INFO/Customer}" numberUnit="{i18n>versionId} {SYS_INFO/Sysid}">
<attributes>
<ObjectAttribute title="{i18n>custName}" text="{jsonData>/FILE_UPD_UI5Set/Customer}"/>
<ObjectAttribute title="{i18n>osDetails}" text="{jsonData>Customer}"/>
<ObjectAttribute title="{i18n>dbDetails}" text="{jsonData>/Value}"/>
</attributes>
</ObjectHeader>
答案 0 :(得分:0)
该错误表明无法调用方法read
,因为它被调用的对象是undefined
。这意味着this.getView().getModel()
会返回undefined
。
据我所知,onInit
生命周期钩子中的视图模型不可用。您必须选择不同的生命周期方法。
可以在API description of the controller class中找到所有生命周期挂钩的列表。
我建议使用onBeforeRendering
,因为它是在onInit
之后直接调用的。
另请参阅描述同一问题的this github issue(并提供一些答案)。