我正在尝试在我的 webapp 中的 manifest.json 中设置一个数据模型。我正在使用 sapui5,我对它很陌生。
我从我的 api 获得的资源是一个 jsonObject 但不知何故模型没有正确启动。我用 console.log() 检查了模型,它是空的。当我对 jsonArray 执行相同操作时,它正在工作。
我应该提到我使用了一个 mockserver.js
这是我正在使用的代码。
清单.json:
"sap.app": {
...
"dataSources": {
"invoiceRemote": {
"uri": "https://services.odata.org/V2/Northwind/Northwind.svc/",
"type": "OData",
"settings": {
"odataVersion": "2.0",
"localUri": "localService/metadata.xml"
}
}
}
}
...
"sap.ui5": {
...
"models": {
"i18n": {
"type": "sap.ui.model.resource.ResourceModel",
"settings": {
"bundleName": "MyInboxUI5.i18n.i18n"
}
},
"invoice": {
"dataSource": "invoiceRemote"
}
...
和 JsonObject 我的意思是这种风格的 .json :
{
"field1": value1,
"field2": value2,
"field3": [
{
"field4": value4,
"field5": value5
},
{
"field6": value6,
"field7": value7
} ]
}
(那是不工作的)
我的意思是 JsonArray
[
{
"field4": value4,
"field5": value5
},
{
"field6": value6,
"field7": value7
}
]
(这个正在工作)
为了检查我的模型,我使用了简单的 console.log()
Component.js(它的一部分)
init: function() {
console.log(this.getModel("invoice"));
UIComponent.prototype.init.apply(this, arguments);
this.getRouter().initialize();
}
我没有发布 mockserver.js 或 metadata.xml,因为我不确定它是否相关并且它们占用了大量空间。
那么有谁知道是否有办法在 manifest.json 中加载 JsonObject 的模型?我知道还有其他可能加载有效的模型,但我只对这种特定情况感兴趣。