cancel
Showing results for 
Search instead for 
Did you mean: 

How to reresh dropdown after new data from odata service "READ"

Former Member
0 Kudos

Hy,

I'am new in the fiori business and i'am struggling with the binding principles.

I created a combox in my XML view with a binding to my odata that has bin loaded by my WEBIDE. I get my list in my dropdown. So far so good but i want to refresh my list after an action by calling the backend again with a parameter. I get a return with different data, but i don't succeed in binding those new items to my drop down. I scanned in my opinion the hole internet but can't find a proper solution.

XML ( view1.xml ) :

<Combobox

id = "expenseID"

items = "{/ExpenseTypes}"

<core:Item key = "{ExpenseTypeID}" tekst = "{Description}"/>

<Combobox>

JS :

sap.ui.controller("view.view1",{

changeExpenseTypes: function(e) {

var model = this.getView().getModel();

var sUrl = "/ExpenseTypes?search=2";

model.read(sUrl, null, null, false, function(data, reponse) {

console.log('success');

console.log(data);

return data; });

}

});

When i call method changeExpenseTypes , i load my allready know model, calling my odata service ExpenseTypes , got a return of 5 new records and then i don't know what to do next to see those new records in my drop down.

Thanks in advance for your help or suggestions  !!

Greetings

Jonas

Accepted Solutions (1)

Accepted Solutions (1)

former_member203031
Contributor
0 Kudos

Hi Jonas,

After fetching the new records,

You need to set the model to the drop down again.

Thanks,

Deepak.

Former Member
0 Kudos

Hy Deepak,

Thanks for your fast response.

Do you mean in the read function or after the model.read ?

Thx. Jonas

former_member203031
Contributor
0 Kudos

In the success function of the  read service which you are fetching for the fresh values.

Former Member
0 Kudos

Problem there is when i’m in the success area that my view isn't know anymore. I can’t load my dropdown for setting values for example.

I would expect that i have to push my values to my model, and the rest would follow like changes in my dropdown.

I tried sap.ui.getCore().setModel(model); in success area also.

former_member203031
Contributor
0 Kudos

var id = sap.ui.getCore().byId("dropdownid")

id.setModel("newmodel")

Then the values will be updated

Former Member
0 Kudos

Hy Deepak,

sap.ui.getCore() is also not know in de success area. When I debug, all code has bin executed and afterwards he returns for the success area, but the view ect. has already bin forgotten.

Grtz Jonas.  

former_member203031
Contributor
0 Kudos

Sorry Jonas.

I didn't get you.

Former Member
0 Kudos

Printscreen off my debugger, here you can see that 'test' and 'id' are empty. They are not reconised within the succes area.

Thx for al the effort !

seVladimirs
Active Contributor
0 Kudos

You can bind "this" (your controller) to the success callback, see sample code below,


changeExpensesTypes: function(e){

    // your code

   

    oModel.read(sUrl, null, null, false, function(data,response){

        // this = your view controller

        var sId = this.getView().byId("expenseID");

       

       

    }.bind(this), function(oError){

       

    });

   

    // your code

}

former_member203031
Contributor
0 Kudos

Hi Jonas,

According to your code:

Hope now you will get the sol

  1. changeExpensesTypes: function(e){ 
  2.     oModel.read(sUrl, null, null, false, function(data,response){ 
  3.     var new_model = new sap.ui.mode.json.JSONModel()
  4. new_model.setdata(data)  //  here data represents the data in the function(data,response)

  5.         var sId = this.getView().byId("expenseID"); 
  6. sId.setModel(new_model)
  7.          
  8.     },
  9. function(oError){ 
  10.          
  11.     }); 
  12.  

Thanks,

Deepak.

Former Member
0 Kudos

Hy Deepak,

I'm almost there, sId.setModel(new_model) works half, he removes the old list and replaces it with nothing. So i guess that i need some template so the combobox can reconise what's texts, id , ... ?

Image of my new_model.

Code :

Thx , Jonas

former_member203031
Contributor
0 Kudos

if possible can you share me the view code to see how you defined the combobox and the path.

Former Member
0 Kudos
former_member203031
Contributor
0 Kudos

Please look at the following example piece of code:

I think you missed the path in your code try by giving the path in the combo box as shown below:

  1. <ComboBox
  2. items="{
  3. path: '/results',
  4. }">
  5. <core:Item key="{ExpensetypeId} text="{Description}" />
  6. </ComboBox>

Thanks,

Deepak.



Former Member
0 Kudos

Hy Deepak,

Thanks for all the effort, it works know ! I'm happy ... 

Reason why i chosen the path /ExpenseTypes is because it is the name of my odata service and with the first run he went directly to the backend for his data. But one off the problems was that my model had an other definition and couldn’t find the new data. ( This is my conclusion ) 

Greetings Jonas

Answers (0)