簡體   English   中英

如何在openui5中將本地文件中的json對象用作數據模型?

[英]How to use a json object from a local file as a datamodel in openui5?

我對示例https://github.com/SAP/openui5-masterdetail-app有問題

我想在文件夾'webapp / localService / mockdata'中使用兩個json文件Objects.json和LineItems.json

我有本地安裝(沒有WEB IDE)。 工作正常。

我進行了以下更改

webapp / manifest.json

...

"resources": "resources.json",
"dataSources": {
    "tableData_alias": {
        "uri": "localService/mockdata/Objects.json",
        "type": "JSON"
    }
}

...

"models": {
    "i18n": {
        "type": "sap.ui.model.resource.ResourceModel",
        "settings": {
            "bundleName": "sap.ui.demo.masterdetail.i18n.i18n"
        }
    },
    "tableData": {
        "type": "sap.ui.model.json.JSONModel",
        "dataSource": "tableData_alias",
        "preload": true
    }
},

webapp / view / Master.view.xml

...
items="{
        path: 'DataModel>/',
        sorter: {
            path: 'Name',
            descending: false
        },
        groupHeaderFactory: '.createGroupHeader'
    }"
...

webapp / controller / Master.controller.js

onInit : function () {
var dataModel = this.getOwnerComponent().getModel("tableData");
this.getView().setModel(dataModel, "DataModel");

// Control state model
var oList = this.byId("list"),
...

文件Objects.json將被加載,但主表未呈現。 (“詳細信息”列表是以后對我的下一步...)

json文件

在瀏覽器的控制台中,我收到以下錯誤:_未能加載容器容器的組件。 原因:TypeError:無法獲取未定義或空引用的屬性'attachMetadataFailed'-_

請幫助,什么不正確。 (也許整個例子在github上?)

webapp/controller/Master.controller.js ,請嘗試在onAfterRendering: function()而不要在onInit: function()

謝謝

請嘗試以下解決方案。 我沒有看到任何代碼錯誤,但是您正在onInit函數中為上下文視圖設置json模型,該模型可能為空。

webapp / view / Master.view.xml中 ,可以使用在manifest.json中定義的模型直接綁定聚合路徑。

 ...
items="{
        path: 'tableData>/',
        sorter: {
            path: 'Name',
            descending: false
        },
        groupHeaderFactory: '.createGroupHeader'
    }"
...

謝謝。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM