[英]SAPUI5 get OData model in controller
我在SAPUI5中做一個簡單的項目,我在控制器中從OData獲取數據時遇到了一些問題。 我猜想js中是否有可能。
我通過目的地與Northwind.svc連接。 我可以僅使用“ {/ Products}”在.view文件中輕松顯示它,但是在.controller文件中沒有任何作用。 我嘗試使用this.getView()。getModel()創建新的sap.ui.model.odata.v2.ODataModel({serviceUrl:“ services.odata.org/Northwind/Northwind.svc”});
一直以來,我想獲得特性,我只是一無所獲。
我的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
}
新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"
}
]
成分: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:
return {
createDeviceModel: function() {
var oModel = new JSONModel(Device);
oModel.setDefaultBindingMode("OneWay");
return oModel;
}
};
任何想法我在做什么錯?
您可以使用getObject
從ODataModel
獲取對象或屬性,例如,可以通過以下方法獲取Email屬性:
oModel.getObject("/Clients(KEY)/Email")
或者,您可以先獲取整個對象,然后訪問Email屬性
oModel.getObject("/Clients(KEY)").Email
樣本響應中的 KEY應該是9000005L
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.