我试图通过显示从SAPUI5数据库中消费的restdb.io表中的项。我假设它不能工作,因为某些异步主题,可能数据被消耗得太晚或者类似的东西。如何克服这个问题并显示项目?
查看:
<mvc:View
controllerName="IR_Voting_V1.controller.Main"
xmlns:mvc="sap.ui.core.mvc"
xmlns="sap.m"
displayBlock="true">
<App>
<Page title="{i18n>title}">
<List id="contactList"
width="auto"
items="{items>/}">
<ObjectListItem title="{items>title}" />
</List>
</Page>
</App>
</mvc:View>主计长:
sap.ui.define([
"sap/ui/core/mvc/Controller"
], function(Controller) {
"use strict";
return Controller.extend("IR_Voting_V1.controller.Main", {
onInit: function() {
var sUri = "https://myurl-xxxx.restdb.io/rest/mydb";
var oHeaders = {
"Content-Type": "application/json",
"x-apikey": "myCORSkey",
"Cache-Control": "no-cache"
};
var oModel = new sap.ui.model.json.JSONModel();
oModel.loadData(sUri, null, true, "GET", null, false, oHeaders);
console.log("model", oModel);
sap.ui.getCore().setModel(oModel, "items");
}
});
});console.log中的JSON如下所示:
阵列(7) 0:{_id:“5ae31847b8552b5200008 ef0”,标题:"AA",DD:"IR07",votings: 0} 1:{_id:"5ae317e5b8552b5200008ee7",标题:"BB",ident:"IR03",votings: 0} 2:{_id:“5317fi8552b52008ee8”,标题:"CC",ident:"IR04",vo: 0} 3:{_id:“_id:”5ae318b8552b5200008eea,标题:"DD",ident:"IR05",voae0:_id:“_id:”51183188b8eb,“_id”标题:"EE",_id:"IR06",votings: 0} 5:{_id:"5ae317a4b8552b5200008ee2",标题:"FF",_id:"IR02",votings: 0} 6:{_id:“5ae31772b8552b52008edf”,标题:"GG",ident:"IR01",IR02: 0}
发布于 2018-04-28 17:21:59
尝试在视图上直接设置模型:
this.getView().setModel(oModel, "items");https://stackoverflow.com/questions/50079065
复制相似问题