[英]SAPUI5 get OData model in controller
i'm making simple project in SAPUI5 and i have some problems with gettin data from OData in controller. 我在SAPUI5中做一个简单的项目,我在控制器中从OData获取数据时遇到了一些问题。 I'm guessin if it is possible in js. 我猜想js中是否有可能。
I am connected with Northwind.svc by destination. 我通过目的地与Northwind.svc连接。 I can easily show it in .view file using just "{/Products}", but nothing works in .controller file. 我可以仅使用“ {/ Products}”在.view文件中轻松显示它,但是在.controller文件中没有任何作用。 I tried to use this.getView().getModel(), creating new sap.ui.model.odata.v2.ODataModel({serviceUrl: "services.odata.org/Northwind/Northwind.svc" }); 我尝试使用this.getView()。getModel()创建新的sap.ui.model.odata.v2.ODataModel({serviceUrl:“ services.odata.org/Northwind/Northwind.svc”});
All the time i want to get propierties i'm just getting null back. 一直以来,我想获得特性,我只是一无所获。
There is piece of my manifest.json file 我的manifest.json文件有一部分
"sap.app": {
"dataSources": {
"Northwind": {
"uri": "/V2/Northwind/Northwind.svc/",
"type": "OData",
"settings": {
"odataVersion": "2.0",
"localUri": "localService/Northwind/metadata.xml"
}
}
}
},
"models": {
"i18n": {
"type": "sap.ui.model.resource.ResourceModel",
"settings": {
"bundleName": "Odczyty.i18n.i18n"
}
},
"": {
"type": "sap.ui.model.odata.v2.ODataModel",
"settings": {
"defaultOperationMode": "Server",
"defaultBindingMode": "Default",
"defaultCountMode": "Request"
},
"dataSource": "Northwind",
"preload": true
}
neo-app.json: 新app.json:
"routes": [
{
"path": "/resources",
"target": {
"type": "service",
"name": "sapui5",
"entryPath": "/resources"
},
"description": "SAPUI5 Resources"
},
{
"path": "/test-resources",
"target": {
"type": "service",
"name": "sapui5",
"entryPath": "/test-resources"
},
"description": "SAPUI5 Test Resources"
},
{
"path": "/V2/Northwind/Northwind.svc/",
"target": {
"type": "destination",
"name": "Northwind"
},
"description": "Northwind OData Service"
}
] ]
Component:js 成分:JS
init: function() {
// call the base component's init function
UIComponent.prototype.init.apply(this, arguments);
// set the device model
this.setModel(models.createDeviceModel(), "device");
}
models.js: models.js:
return {
createDeviceModel: function() {
var oModel = new JSONModel(Device);
oModel.setDefaultBindingMode("OneWay");
return oModel;
}
};
Any ideas what i'm doing wrong? 任何想法我在做什么错?
You can use getObject
to get your object or property from ODataModel
, for example, you can get Email property by following: 您可以使用getObject
从ODataModel
获取对象或属性,例如,可以通过以下方法获取Email属性:
oModel.getObject("/Clients(KEY)/Email")
Or you can get the whole object first then access the Email property 或者,您可以先获取整个对象,然后访问Email属性
oModel.getObject("/Clients(KEY)").Email
KEY should be 9000005L
in your sample response 样本响应中的 KEY应该是9000005L
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.