cancel
Showing results for 
Search instead for 
Did you mean: 

Binding combobox with JSONModel in XML view

VenugopalA
Explorer
0 Kudos

Dear Experts,

request to help in Binding combobox with JSONModel in XML view am using SAP WEB IDE on HCC.


Please refer below screen am trying to get highlighted [ in red ] all Plot numbers in to Combobox, while onload view or on any action i.e. button click event


For that I have declared in XML as :-


And in Controller.js

with this line of code "var oList = oJsonModel.getProperty("/results/1");" am getting Plot number, but i required all plot numbers into comboBox.

would be very kind and appreciated your help.

thank you in advance.

Sid.

Accepted Solutions (1)

Accepted Solutions (1)

SergioG_TX
Active Contributor
0 Kudos

Sid,

are you getting no record at all? or are you getting blank records?  it seems like Sai suggestion would be correct.

when you set the model, are you able to read those records in the model? if so, then what is the model path... based on your screenshots, you should be able to access it by the /d/results path.

and again as per Sai suggestion, the text and key property should be {PlotNo}

one more thing to check would be your _getData function in the controller.. are you correctly building the URL with the filter you are concatenating? please copy that url you are building into the browser and make sure you get some results... make sure the end point is also being called correctly and the BpId is also being read correctly from your call

VenugopalA
Explorer
0 Kudos

Hi Sergio Guerrero,


thank you for your reply,


Am getting records with a specific level Ex.


with below two lines am able read the plotno of /results/1 only, if i change as "/results/2", then am able to read plotno of "result/2", please refer below code:


       var oList = oJsonModel.getProperty("/results/1");

       sap.m.MessageBox.information(oList.PlotNo);

and same Plotno am able to display on information box, using with below line.

sap.m.MessageBox.information(oList.PlotNo);


am able to read BpId, PlotNo, ValidFrom and ValitTo as one record and one entry at a time.

am trying to bind the items with results--> PlotNo with below line please refer:

_getData function in the controller.. yes i have correctly building the URL with the filter, with this binding am getting results/1 of plotnot. in fact i can able to view 8 records in browser level all results, please refer below screen.



above screen there are 8 results with BpId, PlotNo, ValidFrom & ValiTo, from that i required only Plotno 's [ which is 8 ] to be bind with ComboBox.


Thanks to  Mr.Sai, as he suggest I was trying, but still am not getting / not able to bind with results PlotNo values with comboBox.

Regards,

Sid

VenugopalA
Explorer
0 Kudos

Hi,

issue has resolved with below code..

@ViewLevel:-

<ComboBox items="{path: '/results',sorter: { path : 'PlotNo' } }" >

          <core:Item key="{PlotNo}" text="{PlotNo}"/>

</ComboBox>

@controller.js Level:-

oView.setModel(oJsonModel); // was missing this pice of code @__getData: function(){ /// }

thank you Mr. Sai & Sergio Guerrero for your time & inouts.

regards,

sid.

Answers (1)

Answers (1)

saivellanki
Active Contributor
0 Kudos

Hi Sid,

Are you sure you're  getting the value for below statement?


var oList = oJsonModel.getProperty("/results/1");

Can you try something like this:


<ComboBox id="_box0" value="Please Select Sector" items="{/d/results}" selectionChange="_getData">

          <items>

               <core:Item text="{PlotNo}" key="{PlotNo}" />

          </items>

</ComboBox>

Regards,

Sai Vellanki.

VenugopalA
Explorer
0 Kudos

Hi Sai,

Thank you for your reply,

yes am getting using with this line of code "var oList = oJsonModel.getProperty("/results/1");"

here i would like to explain small info i.e. am getting property result on information box just am displaying one entry i.e "results/1".pls refer beow.

var oList = oJsonModel.getProperty("/results/1");

sap.m.MessageBox.information(oList.PlotNo);

same thing i would required to bind with  comboBox. not only the one entry [/results/1], i would required to add all i.e. results of [8].

and i have updated the changes as suggested i.e. items="{/d/results}", still am not getting items into comboBox.

please suggest.

thank you once again.

sid

saivellanki
Active Contributor
0 Kudos

Sid,

Can you try in console something like below and check the structure:


var oModel = sap.ui.getCoree().getModel();

var oData = oModel.getData();

console.log(JSON.stringify(oData));

I tried to create a similar structure like the one you had:


{

              d: {

                  results: [{

                      PlotNo: "26442123889"

                  }, {

                      PlotNo: "24545319221"

                  }, {

                      PlotNo: "23323948312"

                  }, {

                      PlotNo: "27322912139"

                  }, {

                      PlotNo: "28219121132"

                  }, {

                      PlotNo: "28212913212"

                  }, {

                      PlotNo: "27404349303"

                  }, {

                      PlotNo: "27565543454"

                  }]

              }

          };

And I created a sample with Combo Box binding to above model: JS Bin - Collaborative JavaScript Debugging

Hope this should help.

Regards,

Sai Vellanki.

VenugopalA
Explorer
0 Kudos

Hi Sai.

while trying as suggested by you, am getting console.log issue i.e unexpected console statement". for further level i have done similar example i.e.

{

  "staff": [{

  "city": ""

  }, {

        "city": "Berlin",

         "genders": [{

                           "gender": "Berlin Male",

                            "people": [{

                                             "firstName": "1.Berlin.Male.FirstName",

                                              "lastName": "1.Berlin.Male.LastName"

  }, {

  "                                            firstName": "2.Berlin.Male.FirstName",

                                               "lastName": "2.Berlin.Male.LastName"

  }]

  }, {

                           "gender": "Berlin Female",

                           "people": [{

                                             "firstName": "1.Berlin.Female.FirstName",

                                              "lastName": "1.Berlin.Female.LastName"

  }, {

                                               "firstName": "2.Berlin.Female.FirstName",

                                                "lastName": "2.Berlin.Female.LastName"

  }]

  }]

  },

its working with mock JSONModel while trying to get from real JSONModel am not getting same.

for more details am attaching my JSONModel within expand mode please refer the same.

and request to suggest please.

regards,

sid    

VenugopalA
Explorer
0 Kudos

Hi Sai and Sergio Guerrero

please refer below screen, regarding GET response @model before sorting. this might help me to you suggest some inputs.

Thank you .

Regards,

sid.