0
votes

I am trying to pass the values of selected items from multiComboBox to another view to bind it in a table. I am getting the selected values as

selectedItems = oEvent.getParameter("selectedItems");
		

routing code:

{
    "pattern": "data/{value}",
    "name": "page2",
    "target": "page2"
}

oRouter.navTo("page2", {
value : JSON.stringify(selectedItems)
}

and getting it in another controller as:

var output = JSON.parse(oEvent.getParameters("arguments").value);
alert(output);

The error I am getting is Uncaught TypeError: Converting circular structure to JSON

2
selecteditem is a nested object, might contain methods too. it will contain itself, somewhere in there by the sound of things. look inside it in the debugger to see the values you need. - Jorg

2 Answers

3
votes

The problem lies in the fact that the selectedItems parameter of the selectionFinished event is actually an array of sap.ui.core.Item. Most UI5 elements are not serializable, because they hold references to their parents, which in turn hold references to the elements themselves (thus forming a cycle).

In my opinion, you should instead use the selected keys instead of the selected items. You can obtain the keys by simply using the getSelectedKeys method:

var aKeys = oEvent.getSource().getSelectedKeys();

This will return an array of strings, which can be then serialized as you intended. After deserializing the keys, you can use the setSelectedKeys method to restore the selection.

0
votes

Another approach would be to pass the data by setting it in a Global Model instead of passing it as router string. Just my 2 cents. :)