我试图从IoTMMS(SAP云平台服务)获取OData EntitySet的最后一个条目。
谢谢!
{
"welcomeFile": "/webapp/index.html",
"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": "/com.sap.iotservices.mms/v1/api/http/app.svc",
"target": {
"type": "destination",
"name": "sensordata_tut"
},
"description": "sensordata_tut"
}
],
"sendWelcomeFileRedirect": true
}

{
"_version": "1.7.0",
...
"dataSources": {
"sensordata": {
"uri": "/com.sap.iotservices.mms/v1/api/http/app.svc",
"type": "OData",
"settings": {
"odataVersion": "2.0",
"localUri": "localService/metadata.xml"
}
}
}
},
...
"sap.ui5": {
...
},
"contentDensities": {
"compact": true,
"cozy": true
},
"models": {
"i18n": {
"type": "sap.ui.model.resource.ResourceModel",
"settings": {
"bundleName": "sensordata_tut.i18n.i18n"
}
},
"sensordata": {
"dataSource": "sensordata",
"type": "sap.ui.model.odata.v2.ODataModel",
"preload": true
}
},
"resources": {
"css": [{
"uri": "css/style.css"
}]
}
}
}

<mvc:View xmlns:html="http://www.w3.org/1999/xhtml" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" controllerName="sensordata_tut.controller.Master" displayBlock="true">
<App>
<pages>
<Page title="{i18n>title}" content="{sensordata>/T_IOT_4212F80B4D7D95539D0C}">
<content>
<StandardTile title="Sensor 1" info="{sensordata>G_CREATED}" icon="sap-icon://temperature" number="{sensordata>C_TEMP}" numberUnit="Celsius" infoState="Success" id="__tile0"/>
</content>
</Page>
</pages>
</App>
</mvc:View>
&#13;
sap.ui.define([
"sap/ui/core/mvc/Controller"
], function(Controller) {
"use strict";
return Controller.extend("sensordata_tut.controller.Master", {
onInit: function() {
var url = "/com.sap.iotservices.mms/v1/api/http/app.svc";
var oModel = new sap.ui.model.odata.v2.ODataModel(url);
console.log(oModel);
}
});
});
&#13;
答案 0 :(得分:0)
为什么要在onInit中创建新模型?如果在清单中定义模型,则会在“组件”级别中设置它。要检索它,并在控制器中使用它,请执行以下操作:
onInit(){
var myOdataModel = this.getOwnerComponent().getModel("sensordata");
console.log(myOdataModel);
}
如何获取OData EntitySet中的最后一个条目:更新聚合绑定
<Page title="{i18n>title}" content="{path:'sensordata>/T_IOT_4212F80B4D7D95539D0C', sorter:{path: 'G_CREATED', descending: true}, length: 1}">