cancel
Showing results for 
Search instead for 
Did you mean: 

mutiple model bind to RadioButtonGroup

former_member186158
Active Participant
0 Kudos

...

var oModel = new sap.ui.model.json.JSONModel();

            oModel.setData({

            appTypes:[{skey:"P", stext:"岗位代理 "},

                         {skey:"R", stext:"角色代理 "}],

               reasomTypes:[{skey:"A", stext:"公出 "},

                         {skey:"B", stext:"出差 "},

                        {skey:"C", stext:"请假 "},

                    {skey:"D", stext:"其它 "} ],

                        editable: true,

                      selectedIndex: 0

            });

           

            sap.ui.getCore().setModel(oModel,"myList");

            //*********************************

            // RadioButtonGroup

           

            function LBSelect(oEvent){

                var iIndex = oEvent.getParameter("selectedIndex");

                oModel.setProperty("selectedIndex", iIndex);

            };

            var oRBGroup1 = new sap.ui.commons.RadioButtonGroup("RBGEntry1");

            //oRBGroup1.setModel(oModel);

            oRBGroup1.bindProperty("editable", "myList>/editable");

            oRBGroup1.bindProperty("selectedIndex", "myList>/selectedIndex");

            oRBGroup1.attachSelect(LBSelect);

            var oItemTemplate1 = new sap.ui.core.Item();

            oItemTemplate1.bindProperty("key", "skey");

            oItemTemplate1.bindProperty("text", "stext");

            //oItemTemplate1.bindProperty("enabled", "enabled");

            oRBGroup1.bindItems("myList>/appTypes", oItemTemplate1);

            oMatrix.createRow("代理类别", oRBGroup1,null);

         

           

        //oPanel.addButton(b1);

        oPanel.addContent(oMatrix);

...

data bind failed, Anybody help me ?

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

former_member186158
Active Participant
0 Kudos

Thanks, but not work

former_member186158
Active Participant
0 Kudos

I found this from the SAP demokit:

  • When using multiple models, note that these additional models with a specified name currently only support the creation of property bindings and not aggregation bindings. So, if you want to use aggregation bindings, create a model (containing the aggregation data) without a name as documented before, for example: oElement.setModel(oModel); respective: sap.ui.getCore().setModel(oModel);
former_member293602
Active Participant
0 Kudos

Hi Shen,

I've played a litle with your example and tried to use two separate models to create two separate RadioButtonGroups. For me this is working fine. But this might be due to the fact that I'm using the most current SAPUI5 version... . Please find the results of my "experiments" attached as index.html. I hope the necessary SAPUI5 version will be available on your side soon.

Kind Regards, Frank

var oModelappAlias = new sap.ui.model.json.JSONModel();


oModelappAlias.setData({

appTypes : [ {

skey : "P",

stext : "Text for 'P' "   // orig: "岗位代理"

}, {

skey : "R",

stext : "Text for 'R''" // orig: "角色代理"

} ],

editable : true,

selectedIndex : 0

});


sap.ui.getCore().setModel(oModelappAlias,"appAlias");


//*********************************   

// RadioButtonGroup 1

   

function LBSelect(oEvent){

        var iIndex = oEvent.getParameter("selectedIndex");

        oModel.setProperty("selectedIndex", iIndex);

    };


var oRBGroup1 = new sap.ui.commons.RadioButtonGroup("RBGEntry1");

    oRBGroup1.bindProperty("editable", "appAlias>/editable");

    oRBGroup1.bindProperty("selectedIndex", "appAlias>/selectedIndex");

    oRBGroup1.attachSelect(LBSelect);


var oItemTemplate1 = new sap.ui.core.Item();

    oItemTemplate1.bindProperty("key", "appAlias>skey");

    oItemTemplate1.bindProperty("text", "appAlias>stext");

    oRBGroup1.bindItems("appAlias>/appTypes", oItemTemplate1);

  

//*********************************

// RadioButtonGroup 2

var oModelreasomAlias = new sap.ui.model.json.JSONModel();

oModelreasomAlias.setData({

reasomTypes : [ {

skey : "A",

stext : "Text for 'A'" // orig: "公出 "

}, {

skey : "B",

stext : "Text for 'B'" // orig: "出差 "

}, {

skey : "C",

stext : "Text for 'C'" // orig: "请假 "

}, {

skey : "D",

stext : "Text for 'D'" // orig: "其它 "

} ],

editable : true,

selectedIndex : 0

});


sap.ui.getCore().setModel(oModelreasomAlias,"reasomAlias");

   

var oRBGroup2 = new sap.ui.commons.RadioButtonGroup("RBGEntry2");

    oRBGroup2.bindProperty("editable", "reasomAlias>/editable");

 

var oItemTemplate2= new sap.ui.core.Item();

    oItemTemplate2.bindProperty("key", "reasomAlias>skey");

    oItemTemplate2.bindProperty("text", "reasomAlias>stext");


    oRBGroup2.bindItems("reasomAlias>/reasomTypes", oItemTemplate2);

  

    oMatrix = new sap.ui.commons.layout.MatrixLayout();


    oMatrix.createRow("Text in Martix Row", oRBGroup1,oRBGroup2);  // orig: "代理类别"

    oMatrix.placeAt("content");

former_member186158
Active Participant
0 Kudos

After I update library to 1.12.1, it work now.

Thanks a lot.

Answers (4)

Answers (4)

former_member196942
Participant
0 Kudos

Hi Frank,

               Is Multimodelling possible only with JSON model, I tried using it OData but didn't get.

former_member293602
Active Participant
0 Kudos

Hi Priya,

Multimodel Support (see here OpenUI5 SDK - Demo Kit for details) is avaliable for all model types.

Regards, Frank

former_member293602
Active Participant
0 Kudos

Hi Shen,

when you use a model alias like you do with:

sap.ui.getCore().setModel(oModel,"myList");

you need to use this alias "at all places" in the data binding too, e.g.

            oItemTemplate1.bindProperty("key", "myList>skey");

Regards, Frank

former_member186158
Active Participant
0 Kudos

Still not work for multiple model.

former_member186158
Active Participant
0 Kudos

var oModel = new sap.ui.model.json.JSONModel();

            oModel.setData({

            appTypes:[{skey:"P", stext:"岗位代理 "},

                         {skey:"R", stext:"角色代理 "}],

               reasomTypes:[{skey:"A", stext:"公出 "},

                         {skey:"B", stext:"出差 "},

                        {skey:"C", stext:"请假 "},

                    {skey:"D", stext:"其它 "} ],

                        editable: true,

                      selectedIndex: 0

            });

           

           sap.ui.getCore().setModel(oModel,"myList");

            //*********************************

            // RadioButtonGroup

           

            function LBSelect(oEvent){

                var iIndex = oEvent.getParameter("selectedIndex");

                oModel.setProperty("selectedIndex", iIndex);

            };

            var oRBGroup1 = new sap.ui.commons.RadioButtonGroup("RBGEntry1");

            //oRBGroup1.setModel(oModel);

            oRBGroup1.bindProperty("editable", "/editable");

            oRBGroup1.bindProperty("selectedIndex", "/selectedIndex");

            oRBGroup1.attachSelect(LBSelect);

            var oItemTemplate1 = new sap.ui.core.Item();

            oItemTemplate1.bindProperty("key", "skey");

            oItemTemplate1.bindProperty("text", "stext");

            //oItemTemplate1.bindProperty("enabled", "enabled");

            oRBGroup1.bindItems("/appTypes", oItemTemplate1);

            oMatrix.createRow("代理类别", oRBGroup1,null);

         

           

        //oPanel.addButton(b1);

        oPanel.addContent(oMatrix);