how to bind sap.ui.core model into a select list?










1















Need to put a json data like this



 
"marcas":[

"__metadata":
"id":"data id",
"uri":"data url",
"type":"data type"
,
"Codcard":"01",
"Descript":"MasterCard"
,
]



Into a select input like this one...



 var oSelectMarca = new sap.m.Select(
items:
path: "marcas",
template: new sap.ui.core.ListItem(
key: 'Kunnr',
text: 'Descrip'
),
templateShareable: true
,
selectedKey: 'Marca'
);


I'm trying to do it saving this data into a model and then calling it as you can see above,



 var oModelListMarcasTarjeta = new sap.ui.model.json.JSONModel();
var marcas = [
Descrip: "",
Kunnr: ""
];
var sUrlCard = "data url";
var oDataModelCards = new sap.ui.model.odata.ODataModel(sUrlCard, true);

oDataModelCards.read("dataCollection",
async: false,
success: function(oData, response)

$.each(oData.results, function(i, val)
marcas.push(val);
);

oModelListMarcasTarjeta.setData(
'cards': marcas
);

sap.ui.getCore().setModel(oModelListMarcasTarjeta, "marcas");


);


but is not working, any idea what is wrong?



If I set the model direct to the select input, of course works, but for some reason the input doesn't set te value of the selected item in the list.










share|improve this question




























    1















    Need to put a json data like this



     
    "marcas":[

    "__metadata":
    "id":"data id",
    "uri":"data url",
    "type":"data type"
    ,
    "Codcard":"01",
    "Descript":"MasterCard"
    ,
    ]



    Into a select input like this one...



     var oSelectMarca = new sap.m.Select(
    items:
    path: "marcas",
    template: new sap.ui.core.ListItem(
    key: 'Kunnr',
    text: 'Descrip'
    ),
    templateShareable: true
    ,
    selectedKey: 'Marca'
    );


    I'm trying to do it saving this data into a model and then calling it as you can see above,



     var oModelListMarcasTarjeta = new sap.ui.model.json.JSONModel();
    var marcas = [
    Descrip: "",
    Kunnr: ""
    ];
    var sUrlCard = "data url";
    var oDataModelCards = new sap.ui.model.odata.ODataModel(sUrlCard, true);

    oDataModelCards.read("dataCollection",
    async: false,
    success: function(oData, response)

    $.each(oData.results, function(i, val)
    marcas.push(val);
    );

    oModelListMarcasTarjeta.setData(
    'cards': marcas
    );

    sap.ui.getCore().setModel(oModelListMarcasTarjeta, "marcas");


    );


    but is not working, any idea what is wrong?



    If I set the model direct to the select input, of course works, but for some reason the input doesn't set te value of the selected item in the list.










    share|improve this question


























      1












      1








      1








      Need to put a json data like this



       
      "marcas":[

      "__metadata":
      "id":"data id",
      "uri":"data url",
      "type":"data type"
      ,
      "Codcard":"01",
      "Descript":"MasterCard"
      ,
      ]



      Into a select input like this one...



       var oSelectMarca = new sap.m.Select(
      items:
      path: "marcas",
      template: new sap.ui.core.ListItem(
      key: 'Kunnr',
      text: 'Descrip'
      ),
      templateShareable: true
      ,
      selectedKey: 'Marca'
      );


      I'm trying to do it saving this data into a model and then calling it as you can see above,



       var oModelListMarcasTarjeta = new sap.ui.model.json.JSONModel();
      var marcas = [
      Descrip: "",
      Kunnr: ""
      ];
      var sUrlCard = "data url";
      var oDataModelCards = new sap.ui.model.odata.ODataModel(sUrlCard, true);

      oDataModelCards.read("dataCollection",
      async: false,
      success: function(oData, response)

      $.each(oData.results, function(i, val)
      marcas.push(val);
      );

      oModelListMarcasTarjeta.setData(
      'cards': marcas
      );

      sap.ui.getCore().setModel(oModelListMarcasTarjeta, "marcas");


      );


      but is not working, any idea what is wrong?



      If I set the model direct to the select input, of course works, but for some reason the input doesn't set te value of the selected item in the list.










      share|improve this question
















      Need to put a json data like this



       
      "marcas":[

      "__metadata":
      "id":"data id",
      "uri":"data url",
      "type":"data type"
      ,
      "Codcard":"01",
      "Descript":"MasterCard"
      ,
      ]



      Into a select input like this one...



       var oSelectMarca = new sap.m.Select(
      items:
      path: "marcas",
      template: new sap.ui.core.ListItem(
      key: 'Kunnr',
      text: 'Descrip'
      ),
      templateShareable: true
      ,
      selectedKey: 'Marca'
      );


      I'm trying to do it saving this data into a model and then calling it as you can see above,



       var oModelListMarcasTarjeta = new sap.ui.model.json.JSONModel();
      var marcas = [
      Descrip: "",
      Kunnr: ""
      ];
      var sUrlCard = "data url";
      var oDataModelCards = new sap.ui.model.odata.ODataModel(sUrlCard, true);

      oDataModelCards.read("dataCollection",
      async: false,
      success: function(oData, response)

      $.each(oData.results, function(i, val)
      marcas.push(val);
      );

      oModelListMarcasTarjeta.setData(
      'cards': marcas
      );

      sap.ui.getCore().setModel(oModelListMarcasTarjeta, "marcas");


      );


      but is not working, any idea what is wrong?



      If I set the model direct to the select input, of course works, but for some reason the input doesn't set te value of the selected item in the list.







      javascript sapui5






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 13 '18 at 19:25







      devtester

















      asked Nov 13 '18 at 15:39









      devtesterdevtester

      287




      287






















          3 Answers
          3






          active

          oldest

          votes


















          0














          I could figured it out by setting the model direct into the input



           var oSelectMarca = new sap.m.Select(
          items:
          path: "/cards",
          template: new sap.ui.core.ListItem(
          key: 'Kunnr',
          text: 'Descrip'
          ),
          templateShareable: true
          ,
          selectedKey: 'Marca'
          );
          oSelectMarca.setModel(oModelListMarcasTarjeta);





          share|improve this answer






























            0














            The problem with above version is you are giving a name to the model marcas but you are not mentioning it while binding your control with this model.



            When you do not provide any name to the model(like in the answer you have added) it picks the default model as you see while you set the model in the second case it works.



            The same logic will work if you remove the model name like:






            sap.ui.getCore().setModel(oModelListMarcasTarjeta);





            However, this is not at all appreciated to set the models on the core. Always set the models on the view or controls based on the requirement.






            share|improve this answer

























            • I just edited the post so you can see it better, even if I use the name of the model I declared in the core, It doesn't display any data. Don't know why if json is comming ok

              – devtester
              Nov 13 '18 at 19:28











            • did you try by not naming the model you are setting?

              – Nandan Chaturvedi
              Nov 14 '18 at 8:39


















            0














            As your have the model name, you need to use it in the binding path as well



            Let say you have the following JSON data from backend.



            JSON Data




            'cards': [
            'Descrip': "",
            'Kunnr': ""
            ,
            'Descrip': "ss",
            'Kunnr': "asf"
            ,
            'Descrip': "fff",
            'Kunnr': "asdf"
            ,
            'Descrip': "fas",
            'Kunnr': "asdf"
            ,
            'Descrip': "asdfa",
            'Kunnr': "asdfwer"
            ]



            Binding



            var oModelListMarcasTarjeta = new sap.ui.model.json.JSONModel();
            oModelListMarcasTarjeta.setData( //for implementation I am setting the data like this
            'cards': [
            'Descrip': "",
            'Kunnr': ""
            ,
            'Descrip': "ss",
            'Kunnr': "asf"
            ,
            'Descrip': "fff",
            'Kunnr': "asdf"
            ,
            'Descrip': "fas",
            'Kunnr': "asdf"
            ,
            'Descrip': "asdfa",
            'Kunnr': "asdfwer"
            ]
            );
            sap.ui.getCore().setModel(oModelListMarcasTarjeta, "marcas");

            //Use Model name for binding
            var oSelectMarca = new sap.m.Select(
            items:
            path: "marcas>/cards",
            template: new sap.ui.core.ListItem(
            key: 'marcas>Kunnr',
            text: 'marcas>Descrip'
            )

            );





            share|improve this answer
























              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53284500%2fhow-to-bind-sap-ui-core-model-into-a-select-list%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              I could figured it out by setting the model direct into the input



               var oSelectMarca = new sap.m.Select(
              items:
              path: "/cards",
              template: new sap.ui.core.ListItem(
              key: 'Kunnr',
              text: 'Descrip'
              ),
              templateShareable: true
              ,
              selectedKey: 'Marca'
              );
              oSelectMarca.setModel(oModelListMarcasTarjeta);





              share|improve this answer



























                0














                I could figured it out by setting the model direct into the input



                 var oSelectMarca = new sap.m.Select(
                items:
                path: "/cards",
                template: new sap.ui.core.ListItem(
                key: 'Kunnr',
                text: 'Descrip'
                ),
                templateShareable: true
                ,
                selectedKey: 'Marca'
                );
                oSelectMarca.setModel(oModelListMarcasTarjeta);





                share|improve this answer

























                  0












                  0








                  0







                  I could figured it out by setting the model direct into the input



                   var oSelectMarca = new sap.m.Select(
                  items:
                  path: "/cards",
                  template: new sap.ui.core.ListItem(
                  key: 'Kunnr',
                  text: 'Descrip'
                  ),
                  templateShareable: true
                  ,
                  selectedKey: 'Marca'
                  );
                  oSelectMarca.setModel(oModelListMarcasTarjeta);





                  share|improve this answer













                  I could figured it out by setting the model direct into the input



                   var oSelectMarca = new sap.m.Select(
                  items:
                  path: "/cards",
                  template: new sap.ui.core.ListItem(
                  key: 'Kunnr',
                  text: 'Descrip'
                  ),
                  templateShareable: true
                  ,
                  selectedKey: 'Marca'
                  );
                  oSelectMarca.setModel(oModelListMarcasTarjeta);






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 13 '18 at 16:31









                  devtesterdevtester

                  287




                  287























                      0














                      The problem with above version is you are giving a name to the model marcas but you are not mentioning it while binding your control with this model.



                      When you do not provide any name to the model(like in the answer you have added) it picks the default model as you see while you set the model in the second case it works.



                      The same logic will work if you remove the model name like:






                      sap.ui.getCore().setModel(oModelListMarcasTarjeta);





                      However, this is not at all appreciated to set the models on the core. Always set the models on the view or controls based on the requirement.






                      share|improve this answer

























                      • I just edited the post so you can see it better, even if I use the name of the model I declared in the core, It doesn't display any data. Don't know why if json is comming ok

                        – devtester
                        Nov 13 '18 at 19:28











                      • did you try by not naming the model you are setting?

                        – Nandan Chaturvedi
                        Nov 14 '18 at 8:39















                      0














                      The problem with above version is you are giving a name to the model marcas but you are not mentioning it while binding your control with this model.



                      When you do not provide any name to the model(like in the answer you have added) it picks the default model as you see while you set the model in the second case it works.



                      The same logic will work if you remove the model name like:






                      sap.ui.getCore().setModel(oModelListMarcasTarjeta);





                      However, this is not at all appreciated to set the models on the core. Always set the models on the view or controls based on the requirement.






                      share|improve this answer

























                      • I just edited the post so you can see it better, even if I use the name of the model I declared in the core, It doesn't display any data. Don't know why if json is comming ok

                        – devtester
                        Nov 13 '18 at 19:28











                      • did you try by not naming the model you are setting?

                        – Nandan Chaturvedi
                        Nov 14 '18 at 8:39













                      0












                      0








                      0







                      The problem with above version is you are giving a name to the model marcas but you are not mentioning it while binding your control with this model.



                      When you do not provide any name to the model(like in the answer you have added) it picks the default model as you see while you set the model in the second case it works.



                      The same logic will work if you remove the model name like:






                      sap.ui.getCore().setModel(oModelListMarcasTarjeta);





                      However, this is not at all appreciated to set the models on the core. Always set the models on the view or controls based on the requirement.






                      share|improve this answer















                      The problem with above version is you are giving a name to the model marcas but you are not mentioning it while binding your control with this model.



                      When you do not provide any name to the model(like in the answer you have added) it picks the default model as you see while you set the model in the second case it works.



                      The same logic will work if you remove the model name like:






                      sap.ui.getCore().setModel(oModelListMarcasTarjeta);





                      However, this is not at all appreciated to set the models on the core. Always set the models on the view or controls based on the requirement.






                      sap.ui.getCore().setModel(oModelListMarcasTarjeta);





                      sap.ui.getCore().setModel(oModelListMarcasTarjeta);






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Nov 15 '18 at 10:48









                      inizio

                      972512




                      972512










                      answered Nov 13 '18 at 17:28









                      Nandan ChaturvediNandan Chaturvedi

                      597622




                      597622












                      • I just edited the post so you can see it better, even if I use the name of the model I declared in the core, It doesn't display any data. Don't know why if json is comming ok

                        – devtester
                        Nov 13 '18 at 19:28











                      • did you try by not naming the model you are setting?

                        – Nandan Chaturvedi
                        Nov 14 '18 at 8:39

















                      • I just edited the post so you can see it better, even if I use the name of the model I declared in the core, It doesn't display any data. Don't know why if json is comming ok

                        – devtester
                        Nov 13 '18 at 19:28











                      • did you try by not naming the model you are setting?

                        – Nandan Chaturvedi
                        Nov 14 '18 at 8:39
















                      I just edited the post so you can see it better, even if I use the name of the model I declared in the core, It doesn't display any data. Don't know why if json is comming ok

                      – devtester
                      Nov 13 '18 at 19:28





                      I just edited the post so you can see it better, even if I use the name of the model I declared in the core, It doesn't display any data. Don't know why if json is comming ok

                      – devtester
                      Nov 13 '18 at 19:28













                      did you try by not naming the model you are setting?

                      – Nandan Chaturvedi
                      Nov 14 '18 at 8:39





                      did you try by not naming the model you are setting?

                      – Nandan Chaturvedi
                      Nov 14 '18 at 8:39











                      0














                      As your have the model name, you need to use it in the binding path as well



                      Let say you have the following JSON data from backend.



                      JSON Data




                      'cards': [
                      'Descrip': "",
                      'Kunnr': ""
                      ,
                      'Descrip': "ss",
                      'Kunnr': "asf"
                      ,
                      'Descrip': "fff",
                      'Kunnr': "asdf"
                      ,
                      'Descrip': "fas",
                      'Kunnr': "asdf"
                      ,
                      'Descrip': "asdfa",
                      'Kunnr': "asdfwer"
                      ]



                      Binding



                      var oModelListMarcasTarjeta = new sap.ui.model.json.JSONModel();
                      oModelListMarcasTarjeta.setData( //for implementation I am setting the data like this
                      'cards': [
                      'Descrip': "",
                      'Kunnr': ""
                      ,
                      'Descrip': "ss",
                      'Kunnr': "asf"
                      ,
                      'Descrip': "fff",
                      'Kunnr': "asdf"
                      ,
                      'Descrip': "fas",
                      'Kunnr': "asdf"
                      ,
                      'Descrip': "asdfa",
                      'Kunnr': "asdfwer"
                      ]
                      );
                      sap.ui.getCore().setModel(oModelListMarcasTarjeta, "marcas");

                      //Use Model name for binding
                      var oSelectMarca = new sap.m.Select(
                      items:
                      path: "marcas>/cards",
                      template: new sap.ui.core.ListItem(
                      key: 'marcas>Kunnr',
                      text: 'marcas>Descrip'
                      )

                      );





                      share|improve this answer





























                        0














                        As your have the model name, you need to use it in the binding path as well



                        Let say you have the following JSON data from backend.



                        JSON Data




                        'cards': [
                        'Descrip': "",
                        'Kunnr': ""
                        ,
                        'Descrip': "ss",
                        'Kunnr': "asf"
                        ,
                        'Descrip': "fff",
                        'Kunnr': "asdf"
                        ,
                        'Descrip': "fas",
                        'Kunnr': "asdf"
                        ,
                        'Descrip': "asdfa",
                        'Kunnr': "asdfwer"
                        ]



                        Binding



                        var oModelListMarcasTarjeta = new sap.ui.model.json.JSONModel();
                        oModelListMarcasTarjeta.setData( //for implementation I am setting the data like this
                        'cards': [
                        'Descrip': "",
                        'Kunnr': ""
                        ,
                        'Descrip': "ss",
                        'Kunnr': "asf"
                        ,
                        'Descrip': "fff",
                        'Kunnr': "asdf"
                        ,
                        'Descrip': "fas",
                        'Kunnr': "asdf"
                        ,
                        'Descrip': "asdfa",
                        'Kunnr': "asdfwer"
                        ]
                        );
                        sap.ui.getCore().setModel(oModelListMarcasTarjeta, "marcas");

                        //Use Model name for binding
                        var oSelectMarca = new sap.m.Select(
                        items:
                        path: "marcas>/cards",
                        template: new sap.ui.core.ListItem(
                        key: 'marcas>Kunnr',
                        text: 'marcas>Descrip'
                        )

                        );





                        share|improve this answer



























                          0












                          0








                          0







                          As your have the model name, you need to use it in the binding path as well



                          Let say you have the following JSON data from backend.



                          JSON Data




                          'cards': [
                          'Descrip': "",
                          'Kunnr': ""
                          ,
                          'Descrip': "ss",
                          'Kunnr': "asf"
                          ,
                          'Descrip': "fff",
                          'Kunnr': "asdf"
                          ,
                          'Descrip': "fas",
                          'Kunnr': "asdf"
                          ,
                          'Descrip': "asdfa",
                          'Kunnr': "asdfwer"
                          ]



                          Binding



                          var oModelListMarcasTarjeta = new sap.ui.model.json.JSONModel();
                          oModelListMarcasTarjeta.setData( //for implementation I am setting the data like this
                          'cards': [
                          'Descrip': "",
                          'Kunnr': ""
                          ,
                          'Descrip': "ss",
                          'Kunnr': "asf"
                          ,
                          'Descrip': "fff",
                          'Kunnr': "asdf"
                          ,
                          'Descrip': "fas",
                          'Kunnr': "asdf"
                          ,
                          'Descrip': "asdfa",
                          'Kunnr': "asdfwer"
                          ]
                          );
                          sap.ui.getCore().setModel(oModelListMarcasTarjeta, "marcas");

                          //Use Model name for binding
                          var oSelectMarca = new sap.m.Select(
                          items:
                          path: "marcas>/cards",
                          template: new sap.ui.core.ListItem(
                          key: 'marcas>Kunnr',
                          text: 'marcas>Descrip'
                          )

                          );





                          share|improve this answer















                          As your have the model name, you need to use it in the binding path as well



                          Let say you have the following JSON data from backend.



                          JSON Data




                          'cards': [
                          'Descrip': "",
                          'Kunnr': ""
                          ,
                          'Descrip': "ss",
                          'Kunnr': "asf"
                          ,
                          'Descrip': "fff",
                          'Kunnr': "asdf"
                          ,
                          'Descrip': "fas",
                          'Kunnr': "asdf"
                          ,
                          'Descrip': "asdfa",
                          'Kunnr': "asdfwer"
                          ]



                          Binding



                          var oModelListMarcasTarjeta = new sap.ui.model.json.JSONModel();
                          oModelListMarcasTarjeta.setData( //for implementation I am setting the data like this
                          'cards': [
                          'Descrip': "",
                          'Kunnr': ""
                          ,
                          'Descrip': "ss",
                          'Kunnr': "asf"
                          ,
                          'Descrip': "fff",
                          'Kunnr': "asdf"
                          ,
                          'Descrip': "fas",
                          'Kunnr': "asdf"
                          ,
                          'Descrip': "asdfa",
                          'Kunnr': "asdfwer"
                          ]
                          );
                          sap.ui.getCore().setModel(oModelListMarcasTarjeta, "marcas");

                          //Use Model name for binding
                          var oSelectMarca = new sap.m.Select(
                          items:
                          path: "marcas>/cards",
                          template: new sap.ui.core.ListItem(
                          key: 'marcas>Kunnr',
                          text: 'marcas>Descrip'
                          )

                          );






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Nov 15 '18 at 12:54

























                          answered Nov 15 '18 at 10:58









                          inizioinizio

                          972512




                          972512



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53284500%2fhow-to-bind-sap-ui-core-model-into-a-select-list%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Top Tejano songwriter Luis Silva dead of heart attack at 64

                              政党

                              天津地下鉄3号線