Skip to Content
0
Sep 21, 2019 at 08:04 AM

JSON Model + Controller + ObjectList

128 Views

Hello helpful people!


I cannot wrap my head around how to properly use the concept of MVC to bind a simple json format dataset to the List on my Main View.

The View is correctly connected to the controller. I have a working info dialog and responding event handlers in my controller. I

I have not added the model into the manifest.json

My main source are two samples from the sapui5 demo kit

I tried to adapt them and simplify them. Without success, please help!

Main.view.xml

<Panel>
    <List
        headerText="Products"
        class="sapUiResponsiveMargin"
        width="auto"
        items="{product>/products}">
        <items>
            <ObjectListItem
                title="{product>name}"/>
        </items>
    </List>

</Panel>

</mvc:View>

Main.controller.js

        onInit: function () {
            const oModel = new JSONModel("webapp/model/products.json");
            this.getView().setModel(oModel, "products");
        }

products.json

{
    "product":[
            {
                    "category": "fruit",
                    "name": "apple"
            },
            {
                    "category": "vegetables",
                    "name": "carrot"
            }
    ]
}