How to dinamically fill sap.m.Select with data?










0















I need to display some odata's data in a sap.m.Select but don't know why is not working, This is the code I have so far



 var oModel = new sap.ui.model.json.JSONModel();
var data = ;
var sUrlCard = "odata's url";
var oDataModel = new sap.ui.model.odata.ODataModel(sUrlCard, true);

oDataModel.read("CardBrandCollectionSet",
async: false,
success: function(oData, response)


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

oModel.setData(
'card': data
);


sap.ui.getCore().setModel(oModel, "card");
,
error: function(oError)
console.log(oError);


);


table where the select input is located



 var oTable = new sap.m.Table(
mode: oMode,
columns: [

hAlign: 'Center',
header: new Text(
text: "Card"
)

]
);


Select input I need to fill with data



 var oSelectMarca = new sap.m.Select(
items:
path: "/card",
template: new sap.ui.core.ListItem(
key: 'Codcard',
text: 'Descript'
),
templateShareable: true
,
selectedKey: 'Marca'
);









share|improve this question


























    0















    I need to display some odata's data in a sap.m.Select but don't know why is not working, This is the code I have so far



     var oModel = new sap.ui.model.json.JSONModel();
    var data = ;
    var sUrlCard = "odata's url";
    var oDataModel = new sap.ui.model.odata.ODataModel(sUrlCard, true);

    oDataModel.read("CardBrandCollectionSet",
    async: false,
    success: function(oData, response)


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

    oModel.setData(
    'card': data
    );


    sap.ui.getCore().setModel(oModel, "card");
    ,
    error: function(oError)
    console.log(oError);


    );


    table where the select input is located



     var oTable = new sap.m.Table(
    mode: oMode,
    columns: [

    hAlign: 'Center',
    header: new Text(
    text: "Card"
    )

    ]
    );


    Select input I need to fill with data



     var oSelectMarca = new sap.m.Select(
    items:
    path: "/card",
    template: new sap.ui.core.ListItem(
    key: 'Codcard',
    text: 'Descript'
    ),
    templateShareable: true
    ,
    selectedKey: 'Marca'
    );









    share|improve this question
























      0












      0








      0








      I need to display some odata's data in a sap.m.Select but don't know why is not working, This is the code I have so far



       var oModel = new sap.ui.model.json.JSONModel();
      var data = ;
      var sUrlCard = "odata's url";
      var oDataModel = new sap.ui.model.odata.ODataModel(sUrlCard, true);

      oDataModel.read("CardBrandCollectionSet",
      async: false,
      success: function(oData, response)


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

      oModel.setData(
      'card': data
      );


      sap.ui.getCore().setModel(oModel, "card");
      ,
      error: function(oError)
      console.log(oError);


      );


      table where the select input is located



       var oTable = new sap.m.Table(
      mode: oMode,
      columns: [

      hAlign: 'Center',
      header: new Text(
      text: "Card"
      )

      ]
      );


      Select input I need to fill with data



       var oSelectMarca = new sap.m.Select(
      items:
      path: "/card",
      template: new sap.ui.core.ListItem(
      key: 'Codcard',
      text: 'Descript'
      ),
      templateShareable: true
      ,
      selectedKey: 'Marca'
      );









      share|improve this question














      I need to display some odata's data in a sap.m.Select but don't know why is not working, This is the code I have so far



       var oModel = new sap.ui.model.json.JSONModel();
      var data = ;
      var sUrlCard = "odata's url";
      var oDataModel = new sap.ui.model.odata.ODataModel(sUrlCard, true);

      oDataModel.read("CardBrandCollectionSet",
      async: false,
      success: function(oData, response)


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

      oModel.setData(
      'card': data
      );


      sap.ui.getCore().setModel(oModel, "card");
      ,
      error: function(oError)
      console.log(oError);


      );


      table where the select input is located



       var oTable = new sap.m.Table(
      mode: oMode,
      columns: [

      hAlign: 'Center',
      header: new Text(
      text: "Card"
      )

      ]
      );


      Select input I need to fill with data



       var oSelectMarca = new sap.m.Select(
      items:
      path: "/card",
      template: new sap.ui.core.ListItem(
      key: 'Codcard',
      text: 'Descript'
      ),
      templateShareable: true
      ,
      selectedKey: 'Marca'
      );






      javascript sapui5






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 13 '18 at 13:17









      devtesterdevtester

      287




      287






















          2 Answers
          2






          active

          oldest

          votes


















          1














          fist of all you do not want to create your odata model like that, please specify it in your manifest:



          in "sap.app" part:



          "dataSources": 
          "yourRemote":
          "uri": "YOUR_URI",
          "type": "OData",
          "settings":
          "odataVersion": "2.0"





          in "sap.ui5" part:



          "models": 
          "i18n":
          "type": "sap.ui.model.resource.ResourceModel",
          "settings":
          "bundleName": "YOUR_i18n"

          ,
          "remoteModel":
          "dataSource": "yourRemote"




          2nd you dont want to create controls in js, you do that in your xml files:
          https://sapui5.hana.ondemand.com/#/topic/1409791afe4747319a3b23a1e2fc7064
          https://blogs.sap.com/2018/05/01/why-do-we-use-xml-views-rather-js-views-in-sapui5/



          in that your select needs to be bound like that:



          <Select
          id="anID"
          valueState="vsModel>/otherText"
          valueStateText="i18n>someText"
          forceSelection="false"
          items="
          path: 'remoteModel>/CardBrandCollectionSet',
          sorter:
          path: 'Descript'

          ">
          <core:Item key="remoteModel>Codcard" text="remoteModel>Descript" />
          </Select>





          share|improve this answer






























            0














            The binding path of the select control is wrong:



            sap.ui.getCore().setModel(oModel, "card"); // model is set at core with name as card

            $.each(oData.results, function(i, val)
            data.push(val);
            );
            oModel.setData(
            'card': data // setting data in an object with name as card
            );


            var oSelectMarca = new sap.m.Select(
            items:
            path: "card>/card/", //Binding path model name along with array name
            template: new sap.ui.core.ListItem(
            key: 'card>Codcard', // model name with property name
            text: 'card>Descript' // model name with property name
            ),
            templateShareable: true
            ,
            selectedKey: 'card>Marca' // model name with property name
            );





            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%2f53281866%2fhow-to-dinamically-fill-sap-m-select-with-data%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              fist of all you do not want to create your odata model like that, please specify it in your manifest:



              in "sap.app" part:



              "dataSources": 
              "yourRemote":
              "uri": "YOUR_URI",
              "type": "OData",
              "settings":
              "odataVersion": "2.0"





              in "sap.ui5" part:



              "models": 
              "i18n":
              "type": "sap.ui.model.resource.ResourceModel",
              "settings":
              "bundleName": "YOUR_i18n"

              ,
              "remoteModel":
              "dataSource": "yourRemote"




              2nd you dont want to create controls in js, you do that in your xml files:
              https://sapui5.hana.ondemand.com/#/topic/1409791afe4747319a3b23a1e2fc7064
              https://blogs.sap.com/2018/05/01/why-do-we-use-xml-views-rather-js-views-in-sapui5/



              in that your select needs to be bound like that:



              <Select
              id="anID"
              valueState="vsModel>/otherText"
              valueStateText="i18n>someText"
              forceSelection="false"
              items="
              path: 'remoteModel>/CardBrandCollectionSet',
              sorter:
              path: 'Descript'

              ">
              <core:Item key="remoteModel>Codcard" text="remoteModel>Descript" />
              </Select>





              share|improve this answer



























                1














                fist of all you do not want to create your odata model like that, please specify it in your manifest:



                in "sap.app" part:



                "dataSources": 
                "yourRemote":
                "uri": "YOUR_URI",
                "type": "OData",
                "settings":
                "odataVersion": "2.0"





                in "sap.ui5" part:



                "models": 
                "i18n":
                "type": "sap.ui.model.resource.ResourceModel",
                "settings":
                "bundleName": "YOUR_i18n"

                ,
                "remoteModel":
                "dataSource": "yourRemote"




                2nd you dont want to create controls in js, you do that in your xml files:
                https://sapui5.hana.ondemand.com/#/topic/1409791afe4747319a3b23a1e2fc7064
                https://blogs.sap.com/2018/05/01/why-do-we-use-xml-views-rather-js-views-in-sapui5/



                in that your select needs to be bound like that:



                <Select
                id="anID"
                valueState="vsModel>/otherText"
                valueStateText="i18n>someText"
                forceSelection="false"
                items="
                path: 'remoteModel>/CardBrandCollectionSet',
                sorter:
                path: 'Descript'

                ">
                <core:Item key="remoteModel>Codcard" text="remoteModel>Descript" />
                </Select>





                share|improve this answer

























                  1












                  1








                  1







                  fist of all you do not want to create your odata model like that, please specify it in your manifest:



                  in "sap.app" part:



                  "dataSources": 
                  "yourRemote":
                  "uri": "YOUR_URI",
                  "type": "OData",
                  "settings":
                  "odataVersion": "2.0"





                  in "sap.ui5" part:



                  "models": 
                  "i18n":
                  "type": "sap.ui.model.resource.ResourceModel",
                  "settings":
                  "bundleName": "YOUR_i18n"

                  ,
                  "remoteModel":
                  "dataSource": "yourRemote"




                  2nd you dont want to create controls in js, you do that in your xml files:
                  https://sapui5.hana.ondemand.com/#/topic/1409791afe4747319a3b23a1e2fc7064
                  https://blogs.sap.com/2018/05/01/why-do-we-use-xml-views-rather-js-views-in-sapui5/



                  in that your select needs to be bound like that:



                  <Select
                  id="anID"
                  valueState="vsModel>/otherText"
                  valueStateText="i18n>someText"
                  forceSelection="false"
                  items="
                  path: 'remoteModel>/CardBrandCollectionSet',
                  sorter:
                  path: 'Descript'

                  ">
                  <core:Item key="remoteModel>Codcard" text="remoteModel>Descript" />
                  </Select>





                  share|improve this answer













                  fist of all you do not want to create your odata model like that, please specify it in your manifest:



                  in "sap.app" part:



                  "dataSources": 
                  "yourRemote":
                  "uri": "YOUR_URI",
                  "type": "OData",
                  "settings":
                  "odataVersion": "2.0"





                  in "sap.ui5" part:



                  "models": 
                  "i18n":
                  "type": "sap.ui.model.resource.ResourceModel",
                  "settings":
                  "bundleName": "YOUR_i18n"

                  ,
                  "remoteModel":
                  "dataSource": "yourRemote"




                  2nd you dont want to create controls in js, you do that in your xml files:
                  https://sapui5.hana.ondemand.com/#/topic/1409791afe4747319a3b23a1e2fc7064
                  https://blogs.sap.com/2018/05/01/why-do-we-use-xml-views-rather-js-views-in-sapui5/



                  in that your select needs to be bound like that:



                  <Select
                  id="anID"
                  valueState="vsModel>/otherText"
                  valueStateText="i18n>someText"
                  forceSelection="false"
                  items="
                  path: 'remoteModel>/CardBrandCollectionSet',
                  sorter:
                  path: 'Descript'

                  ">
                  <core:Item key="remoteModel>Codcard" text="remoteModel>Descript" />
                  </Select>






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 13 '18 at 13:54









                  ErchErch

                  436213




                  436213























                      0














                      The binding path of the select control is wrong:



                      sap.ui.getCore().setModel(oModel, "card"); // model is set at core with name as card

                      $.each(oData.results, function(i, val)
                      data.push(val);
                      );
                      oModel.setData(
                      'card': data // setting data in an object with name as card
                      );


                      var oSelectMarca = new sap.m.Select(
                      items:
                      path: "card>/card/", //Binding path model name along with array name
                      template: new sap.ui.core.ListItem(
                      key: 'card>Codcard', // model name with property name
                      text: 'card>Descript' // model name with property name
                      ),
                      templateShareable: true
                      ,
                      selectedKey: 'card>Marca' // model name with property name
                      );





                      share|improve this answer



























                        0














                        The binding path of the select control is wrong:



                        sap.ui.getCore().setModel(oModel, "card"); // model is set at core with name as card

                        $.each(oData.results, function(i, val)
                        data.push(val);
                        );
                        oModel.setData(
                        'card': data // setting data in an object with name as card
                        );


                        var oSelectMarca = new sap.m.Select(
                        items:
                        path: "card>/card/", //Binding path model name along with array name
                        template: new sap.ui.core.ListItem(
                        key: 'card>Codcard', // model name with property name
                        text: 'card>Descript' // model name with property name
                        ),
                        templateShareable: true
                        ,
                        selectedKey: 'card>Marca' // model name with property name
                        );





                        share|improve this answer

























                          0












                          0








                          0







                          The binding path of the select control is wrong:



                          sap.ui.getCore().setModel(oModel, "card"); // model is set at core with name as card

                          $.each(oData.results, function(i, val)
                          data.push(val);
                          );
                          oModel.setData(
                          'card': data // setting data in an object with name as card
                          );


                          var oSelectMarca = new sap.m.Select(
                          items:
                          path: "card>/card/", //Binding path model name along with array name
                          template: new sap.ui.core.ListItem(
                          key: 'card>Codcard', // model name with property name
                          text: 'card>Descript' // model name with property name
                          ),
                          templateShareable: true
                          ,
                          selectedKey: 'card>Marca' // model name with property name
                          );





                          share|improve this answer













                          The binding path of the select control is wrong:



                          sap.ui.getCore().setModel(oModel, "card"); // model is set at core with name as card

                          $.each(oData.results, function(i, val)
                          data.push(val);
                          );
                          oModel.setData(
                          'card': data // setting data in an object with name as card
                          );


                          var oSelectMarca = new sap.m.Select(
                          items:
                          path: "card>/card/", //Binding path model name along with array name
                          template: new sap.ui.core.ListItem(
                          key: 'card>Codcard', // model name with property name
                          text: 'card>Descript' // model name with property name
                          ),
                          templateShareable: true
                          ,
                          selectedKey: 'card>Marca' // model name with property name
                          );






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 14 '18 at 5:30









                          SaddamhussainSaddamhussain

                          650411




                          650411



























                              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%2f53281866%2fhow-to-dinamically-fill-sap-m-select-with-data%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号線