cancel
Showing results for 
Search instead for 
Did you mean: 

How to reset data binding path of MultiCombobox?

Former Member
0 Kudos

Hi,

I bind a json model to sap.ui.core, as well as 2 initialed controls: sap.m.select & sap.m.MultiCombobox. The Latter needs to change the binding path everytime the former is selected.

My current solution:


  var select= evt.getSource();      //sap.m.select

  var mcb = sap.ui.getCore().byId("mcb_train");        //sap.m.MultiCombobox

  var path = "/changedPath";

  

  mcb .removeAggregation();

  mcb .removeAllItems(); //can't leave out this, why ?

  mcb .bindAggregation("items", path,new sap.ui.core.Item({key:"{key}",text : "{text}"}));

// train.rerender(); //no difference

  },

Result description:

When I select an item of sap.m.select, the data of sap.m.MultiCombobox can change and display correctly.

But If I check a box in the MultiCombobox before, then each time it changes path, the corresponding items will be checked in advance. It seems the attribute "selectedKeys" never change. And I can't clear it.

Further more, the text value won't change, too. It remains the value of the box I check in the first place, no matter what I check after that, it just won't change.

Here's my additional question:

1.What's the difference between removeAggregation() & unbindAggregation() & destroyAggregation() ? Do they work? Cause when I output mAggregation attribute in the console, it seems not change.

2.If I don't use removeAllItems(), then once I check a box in the MultiCombobox, then, after I select on the sap.m.select, the MultiCombobox won't be able to display any json data. Instead, it displays an item with text "no data". In console I can see the binding path doesn't change as requested. Why?

3.Is there any better realization?

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member182862
Active Contributor
0 Kudos

Hi Jocy

I cannot figure out what you are trying to do? Can you create a small example in JSBin to show you issue?

Thanks

-D

Former Member
0 Kudos

Hi Dennis,

Please see example code. In here it works well because of the change of data source. If you use a .json file rather than json object as data source ( I don't know how to do it in JSBin), bugs appear as I mentioned above.

Here's a simple test case using .json file as data source, hope it helps to make me understood:

Step1. select "item 0" , and check "mcb0_0" & "mcb0_1".

Step2. select "item 1". See what happens.

Result:

1."mcb1_0" & "mcb1_1" are automatically selected.------- WRONG.

2. The value of MultiComboBox is mcb0_0mcb0_1.--------WRONG.

Former Member
0 Kudos

Hi Dennis,

I think I know why....

just need to add one line code: MultiCombobox.removeAllSelectedItems(), then everything is okay.