Quantcast
Channel: SCN : Discussion List - SAP HANA Developer Center
Viewing all articles
Browse latest Browse all 6412

Complex Model Binding

$
0
0

I have a JSON model like this one

 

"

{

    "views": [

        {

            "name": "Lelian's View",

            "fields": [

                {

                    "fieldname": "CENTER_TYPE"

                },

                {

                    "fieldname": "EDU_LEVEL"

                },

                {

                    "fieldname": "GENDER_M"

                },

                {

                    "fieldname": "STORE_NAME"

                }

            ]

        },

        {

            "name": "New View",

            "fields": [

                {

                    "fieldname": "AGE"

                },

                {

                    "fieldname": "CUSTOMER_COUNT"

                },

                {

                    "fieldname": "GENDER_F"

                },

                {

                    "fieldname": "HOMEOWNER_Y"

                },

                {

                    "fieldname": "STORE_SK"

                }

            ]

        }

    ]

}"

 

I want to bind a dropdownbox to the "name"s of these views and then bind another dropdownbox with the "fields" of the selected view.

 

But I'm unable to dinamically make that second binding.

 

This is the code in the view:

 

     oViewModel.loadData('services/getViewsForTrialDesign.xsjs');

    var oViewDropdown = new sap.ui.commons.DropdownBox('designViewDropdown', {width: '100%'});

    oViewDropdown.setModel(oViewModel);

    var oViewDropdownItemTemplate = new sap.ui.core.ListItem();

    oViewDropdownItemTemplate.bindProperty("text", "name");

    oViewDropdown.bindItems("/views", oViewDropdownItemTemplate);

    oViewDropdown.onselect = oController.viewNameUpdate;

    var oViewLabel = new sap.ui.commons.Label('designViewLabel',{text:"Select view:", labelFor: oViewDropdown});

    var oGroupByDropdown = new sap.ui.commons.DropdownBox('designGroupByDropdown', {width: '100%'});

    oGroupByDropdown.setModel(oViewModel);

    var oGroupByDropdownTemplate = new sap.ui.core.ListItem();

    oGroupByDropdownTemplate.bindProperty("text", "{fieldname}");

    oGroupByDropdown.bindItems("/views/fields", oGroupByDropdownTemplate);

 

 

And in the controller on the change event of the first dropdownbox, this is the code

 

     var oViewDropdown = sap.ui.getCore().byId('designViewDropdown');

     var oGroupByDropdown = sap.ui.getCore().byId('designGroupByDropdown');

     oGroupByDropdown.setBindingContext(sap.ui.getCore().byId(oViewDropdown.getSelectedItemId()).getBindingContext());

 

Any ideas of how I can achieve this?

 

Thanks in advance.


Viewing all articles
Browse latest Browse all 6412

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>