Can't able to set selectedKey value in a sap.m.Select list? [duplicate]












0
















This question is an exact duplicate of:




  • How to get selectedKey of sap.m.Select from outside?

    4 answers




I am trying to bind some JSON data in a sap select list and is working fine, the issue comes when I actually pick one of the options in the list, for some reason this one is not being selected. The input field just remains in blank



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");

//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}'
})
},
selectedKey: '{Kunnr}', //Here's my problem
});
});


In fact, if I remove the selectedKey from the new sap.m.Select, the options I select work fine and they appear selected in the input, but once I add the property selectedKey it gets broken and no option can be selected.



Any idea why its happening?










share|improve this question















marked as duplicate by Boghyon Hoffmann, Community Dec 14 '18 at 20:26


This question was marked as an exact duplicate of an existing question.























    0
















    This question is an exact duplicate of:




    • How to get selectedKey of sap.m.Select from outside?

      4 answers




    I am trying to bind some JSON data in a sap select list and is working fine, the issue comes when I actually pick one of the options in the list, for some reason this one is not being selected. The input field just remains in blank



    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");

    //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}'
    })
    },
    selectedKey: '{Kunnr}', //Here's my problem
    });
    });


    In fact, if I remove the selectedKey from the new sap.m.Select, the options I select work fine and they appear selected in the input, but once I add the property selectedKey it gets broken and no option can be selected.



    Any idea why its happening?










    share|improve this question















    marked as duplicate by Boghyon Hoffmann, Community Dec 14 '18 at 20:26


    This question was marked as an exact duplicate of an existing question.





















      0












      0








      0









      This question is an exact duplicate of:




      • How to get selectedKey of sap.m.Select from outside?

        4 answers




      I am trying to bind some JSON data in a sap select list and is working fine, the issue comes when I actually pick one of the options in the list, for some reason this one is not being selected. The input field just remains in blank



      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");

      //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}'
      })
      },
      selectedKey: '{Kunnr}', //Here's my problem
      });
      });


      In fact, if I remove the selectedKey from the new sap.m.Select, the options I select work fine and they appear selected in the input, but once I add the property selectedKey it gets broken and no option can be selected.



      Any idea why its happening?










      share|improve this question

















      This question is an exact duplicate of:




      • How to get selectedKey of sap.m.Select from outside?

        4 answers




      I am trying to bind some JSON data in a sap select list and is working fine, the issue comes when I actually pick one of the options in the list, for some reason this one is not being selected. The input field just remains in blank



      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");

      //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}'
      })
      },
      selectedKey: '{Kunnr}', //Here's my problem
      });
      });


      In fact, if I remove the selectedKey from the new sap.m.Select, the options I select work fine and they appear selected in the input, but once I add the property selectedKey it gets broken and no option can be selected.



      Any idea why its happening?





      This question is an exact duplicate of:




      • How to get selectedKey of sap.m.Select from outside?

        4 answers








      javascript select sapui5






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 '18 at 14:29









      inizio

      984512




      984512










      asked Nov 20 '18 at 14:52









      devtesterdevtester

      287




      287




      marked as duplicate by Boghyon Hoffmann, Community Dec 14 '18 at 20:26


      This question was marked as an exact duplicate of an existing question.









      marked as duplicate by Boghyon Hoffmann, Community Dec 14 '18 at 20:26


      This question was marked as an exact duplicate of an existing question.


























          3 Answers
          3






          active

          oldest

          votes


















          0














          You have to specify the model path as well



          var oSelectMarca = new sap.m.Select({
          items: {
          path: "marcas>/cards",
          template: new sap.ui.core.ListItem({
          key: '{marcas>Kunnr}',
          text: '{marcas>Descrip}'
          })
          },
          selectedKey: '{marcas>/cards/1/Kunnr}', //Your solution
          });





          share|improve this answer































            0














            In your sap.m.Select - selectedKey you have to specify which key you want selected from your JSON object, right now you're trying to select the property Kunnr and that's what is breaking your code. It's also preferred if you select a unique property from your object, I can see that there are a couple of entries with the same Kunnr in your JSON.



            Notes:




            • If duplicate keys exist, the first item matching the key is used.

            • If invalid or none selectedKey is used, the first item is being
              selected.

            • Invalid or missing selectedKey leads to severe functional issues in
              sap.m.Table, when the sap.m.Select is used inside a sap.m.Table
              column.


            Following your example:



            My Controller:



                    var oModelListMarcasTarjeta = this.getView().getModel("testModel");
            oModelListMarcasTarjeta.setData({
            "cards": [{
            "Descrip": "",
            "Kunnr": ""
            }, {
            "Descrip": "ss",
            "Kunnr": "asf"
            }, {
            "Descrip": "fff",
            "Kunnr": "asdf"
            }, {
            "Descrip": "fas",
            "Kunnr": "asdf"
            }, {
            "Descrip": "asdfa",
            "Kunnr": "asdfwer"
            }]
            });


            My XML View:



            <Select forceSelection="false" selectedKey="{testModel>/cards/4/Kunnr}"
            items="{ path: 'testModel>/cards',
            sorter: { path: 'Kunnr' } }">
            <core:Item key="{testModel>Kunnr}" text="{testModel>Descrip}"/>
            </Select>


            Note the: selectedKey="{testModel>/cards/4/Kunnr}" this will mean that the 5th entry in the Json object will be selected by default. You should also set forceSelection="false" for better interoperability with data binding.



            Hope this helps!






            share|improve this answer

































              -1














              I solved it by accesing to the properties from outside using the sap core:



              var myvar = sap.ui.getCore().getModel("marcas");
              var selectedKey= myvar.getProperty('/cards/Kunnr');





              share|improve this answer






























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                0














                You have to specify the model path as well



                var oSelectMarca = new sap.m.Select({
                items: {
                path: "marcas>/cards",
                template: new sap.ui.core.ListItem({
                key: '{marcas>Kunnr}',
                text: '{marcas>Descrip}'
                })
                },
                selectedKey: '{marcas>/cards/1/Kunnr}', //Your solution
                });





                share|improve this answer




























                  0














                  You have to specify the model path as well



                  var oSelectMarca = new sap.m.Select({
                  items: {
                  path: "marcas>/cards",
                  template: new sap.ui.core.ListItem({
                  key: '{marcas>Kunnr}',
                  text: '{marcas>Descrip}'
                  })
                  },
                  selectedKey: '{marcas>/cards/1/Kunnr}', //Your solution
                  });





                  share|improve this answer


























                    0












                    0








                    0







                    You have to specify the model path as well



                    var oSelectMarca = new sap.m.Select({
                    items: {
                    path: "marcas>/cards",
                    template: new sap.ui.core.ListItem({
                    key: '{marcas>Kunnr}',
                    text: '{marcas>Descrip}'
                    })
                    },
                    selectedKey: '{marcas>/cards/1/Kunnr}', //Your solution
                    });





                    share|improve this answer













                    You have to specify the model path as well



                    var oSelectMarca = new sap.m.Select({
                    items: {
                    path: "marcas>/cards",
                    template: new sap.ui.core.ListItem({
                    key: '{marcas>Kunnr}',
                    text: '{marcas>Descrip}'
                    })
                    },
                    selectedKey: '{marcas>/cards/1/Kunnr}', //Your solution
                    });






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 22 '18 at 12:51









                    inizioinizio

                    984512




                    984512

























                        0














                        In your sap.m.Select - selectedKey you have to specify which key you want selected from your JSON object, right now you're trying to select the property Kunnr and that's what is breaking your code. It's also preferred if you select a unique property from your object, I can see that there are a couple of entries with the same Kunnr in your JSON.



                        Notes:




                        • If duplicate keys exist, the first item matching the key is used.

                        • If invalid or none selectedKey is used, the first item is being
                          selected.

                        • Invalid or missing selectedKey leads to severe functional issues in
                          sap.m.Table, when the sap.m.Select is used inside a sap.m.Table
                          column.


                        Following your example:



                        My Controller:



                                var oModelListMarcasTarjeta = this.getView().getModel("testModel");
                        oModelListMarcasTarjeta.setData({
                        "cards": [{
                        "Descrip": "",
                        "Kunnr": ""
                        }, {
                        "Descrip": "ss",
                        "Kunnr": "asf"
                        }, {
                        "Descrip": "fff",
                        "Kunnr": "asdf"
                        }, {
                        "Descrip": "fas",
                        "Kunnr": "asdf"
                        }, {
                        "Descrip": "asdfa",
                        "Kunnr": "asdfwer"
                        }]
                        });


                        My XML View:



                        <Select forceSelection="false" selectedKey="{testModel>/cards/4/Kunnr}"
                        items="{ path: 'testModel>/cards',
                        sorter: { path: 'Kunnr' } }">
                        <core:Item key="{testModel>Kunnr}" text="{testModel>Descrip}"/>
                        </Select>


                        Note the: selectedKey="{testModel>/cards/4/Kunnr}" this will mean that the 5th entry in the Json object will be selected by default. You should also set forceSelection="false" for better interoperability with data binding.



                        Hope this helps!






                        share|improve this answer






























                          0














                          In your sap.m.Select - selectedKey you have to specify which key you want selected from your JSON object, right now you're trying to select the property Kunnr and that's what is breaking your code. It's also preferred if you select a unique property from your object, I can see that there are a couple of entries with the same Kunnr in your JSON.



                          Notes:




                          • If duplicate keys exist, the first item matching the key is used.

                          • If invalid or none selectedKey is used, the first item is being
                            selected.

                          • Invalid or missing selectedKey leads to severe functional issues in
                            sap.m.Table, when the sap.m.Select is used inside a sap.m.Table
                            column.


                          Following your example:



                          My Controller:



                                  var oModelListMarcasTarjeta = this.getView().getModel("testModel");
                          oModelListMarcasTarjeta.setData({
                          "cards": [{
                          "Descrip": "",
                          "Kunnr": ""
                          }, {
                          "Descrip": "ss",
                          "Kunnr": "asf"
                          }, {
                          "Descrip": "fff",
                          "Kunnr": "asdf"
                          }, {
                          "Descrip": "fas",
                          "Kunnr": "asdf"
                          }, {
                          "Descrip": "asdfa",
                          "Kunnr": "asdfwer"
                          }]
                          });


                          My XML View:



                          <Select forceSelection="false" selectedKey="{testModel>/cards/4/Kunnr}"
                          items="{ path: 'testModel>/cards',
                          sorter: { path: 'Kunnr' } }">
                          <core:Item key="{testModel>Kunnr}" text="{testModel>Descrip}"/>
                          </Select>


                          Note the: selectedKey="{testModel>/cards/4/Kunnr}" this will mean that the 5th entry in the Json object will be selected by default. You should also set forceSelection="false" for better interoperability with data binding.



                          Hope this helps!






                          share|improve this answer




























                            0












                            0








                            0







                            In your sap.m.Select - selectedKey you have to specify which key you want selected from your JSON object, right now you're trying to select the property Kunnr and that's what is breaking your code. It's also preferred if you select a unique property from your object, I can see that there are a couple of entries with the same Kunnr in your JSON.



                            Notes:




                            • If duplicate keys exist, the first item matching the key is used.

                            • If invalid or none selectedKey is used, the first item is being
                              selected.

                            • Invalid or missing selectedKey leads to severe functional issues in
                              sap.m.Table, when the sap.m.Select is used inside a sap.m.Table
                              column.


                            Following your example:



                            My Controller:



                                    var oModelListMarcasTarjeta = this.getView().getModel("testModel");
                            oModelListMarcasTarjeta.setData({
                            "cards": [{
                            "Descrip": "",
                            "Kunnr": ""
                            }, {
                            "Descrip": "ss",
                            "Kunnr": "asf"
                            }, {
                            "Descrip": "fff",
                            "Kunnr": "asdf"
                            }, {
                            "Descrip": "fas",
                            "Kunnr": "asdf"
                            }, {
                            "Descrip": "asdfa",
                            "Kunnr": "asdfwer"
                            }]
                            });


                            My XML View:



                            <Select forceSelection="false" selectedKey="{testModel>/cards/4/Kunnr}"
                            items="{ path: 'testModel>/cards',
                            sorter: { path: 'Kunnr' } }">
                            <core:Item key="{testModel>Kunnr}" text="{testModel>Descrip}"/>
                            </Select>


                            Note the: selectedKey="{testModel>/cards/4/Kunnr}" this will mean that the 5th entry in the Json object will be selected by default. You should also set forceSelection="false" for better interoperability with data binding.



                            Hope this helps!






                            share|improve this answer















                            In your sap.m.Select - selectedKey you have to specify which key you want selected from your JSON object, right now you're trying to select the property Kunnr and that's what is breaking your code. It's also preferred if you select a unique property from your object, I can see that there are a couple of entries with the same Kunnr in your JSON.



                            Notes:




                            • If duplicate keys exist, the first item matching the key is used.

                            • If invalid or none selectedKey is used, the first item is being
                              selected.

                            • Invalid or missing selectedKey leads to severe functional issues in
                              sap.m.Table, when the sap.m.Select is used inside a sap.m.Table
                              column.


                            Following your example:



                            My Controller:



                                    var oModelListMarcasTarjeta = this.getView().getModel("testModel");
                            oModelListMarcasTarjeta.setData({
                            "cards": [{
                            "Descrip": "",
                            "Kunnr": ""
                            }, {
                            "Descrip": "ss",
                            "Kunnr": "asf"
                            }, {
                            "Descrip": "fff",
                            "Kunnr": "asdf"
                            }, {
                            "Descrip": "fas",
                            "Kunnr": "asdf"
                            }, {
                            "Descrip": "asdfa",
                            "Kunnr": "asdfwer"
                            }]
                            });


                            My XML View:



                            <Select forceSelection="false" selectedKey="{testModel>/cards/4/Kunnr}"
                            items="{ path: 'testModel>/cards',
                            sorter: { path: 'Kunnr' } }">
                            <core:Item key="{testModel>Kunnr}" text="{testModel>Descrip}"/>
                            </Select>


                            Note the: selectedKey="{testModel>/cards/4/Kunnr}" this will mean that the 5th entry in the Json object will be selected by default. You should also set forceSelection="false" for better interoperability with data binding.



                            Hope this helps!







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Nov 22 '18 at 13:33









                            inizio

                            984512




                            984512










                            answered Nov 20 '18 at 15:32









                            Andre FAndre F

                            296213




                            296213























                                -1














                                I solved it by accesing to the properties from outside using the sap core:



                                var myvar = sap.ui.getCore().getModel("marcas");
                                var selectedKey= myvar.getProperty('/cards/Kunnr');





                                share|improve this answer




























                                  -1














                                  I solved it by accesing to the properties from outside using the sap core:



                                  var myvar = sap.ui.getCore().getModel("marcas");
                                  var selectedKey= myvar.getProperty('/cards/Kunnr');





                                  share|improve this answer


























                                    -1












                                    -1








                                    -1







                                    I solved it by accesing to the properties from outside using the sap core:



                                    var myvar = sap.ui.getCore().getModel("marcas");
                                    var selectedKey= myvar.getProperty('/cards/Kunnr');





                                    share|improve this answer













                                    I solved it by accesing to the properties from outside using the sap core:



                                    var myvar = sap.ui.getCore().getModel("marcas");
                                    var selectedKey= myvar.getProperty('/cards/Kunnr');






                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Dec 12 '18 at 21:41









                                    devtesterdevtester

                                    287




                                    287















                                        Popular posts from this blog

                                        MongoDB - Not Authorized To Execute Command

                                        in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

                                        Npm cannot find a required file even through it is in the searched directory