cancel
Showing results for 
Search instead for 
Did you mean: 

How to pass array values(from multiComboBox) in routing

janani_10
Explorer
0 Kudos

Hi,

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

view1.controller.js code:

var selectedItems = [];
selectedItems = oEvent.getParameter("selectedItems"); 

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

manifest.json code:

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

view2.controller.js code:

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

I am getting the error as

Uncaught TypeError: Converting circular structure to JSON

Can any one help me with this?

Thanks,

Janani

Accepted Solutions (0)

Answers (3)

Answers (3)

junwu
Active Contributor

just put it in model, no need to pass through url

former_member186734
Active Participant
0 Kudos

I agree! You can define the filters directly in the Odata model and the routed view will present the filtered data.

janani_10
Explorer

Hi,

It will be helpful if you refer me some blogs related to this.

Thanks,

Janani

francesco_alborghetti
Active Participant
0 Kudos

Since selected items is an array of objects with circular reference, i don't think you can stringify it:

Is not an array with key and text enough?

var selectedItems = oEvt.getParameter("selectedItems"); 
      var selectedKeys = [];
      for (var i=0; i<selectedItems.length; i++) {
      	selectedKeys.push({key: selectedItems[i].getProperty("key"), "text": selectedItems[i].getProperty("text")});
      }
      console.log(JSON.stringify(selectedKeys));
janani_10
Explorer
0 Kudos

Hi Francesco,

With console.log(JSON.stringify(selectedKeys));

I am getting key value pair of the selected items as array of objects. I need to pass this object values to another view to bind it in a table. While passing it in the route section as

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

I am getting error as Uncaught SyntaxError: Unexpected token u in JSON at position 0


Thanks,

Janani

francesco_alborghetti
Active Participant
0 Kudos

Hi Janani,

Unexpected token u in JSON at position 0 means JSON is undefined (u at 0).

Do you get this error message in JSON.parse on second view?

janani_10
Explorer
0 Kudos

Hi Francesco,

Yes, I am getting the error message in JSON.parse on the second view

ericci
Active Contributor
0 Kudos

Hi Janani, can you also print the content of the JSON?

I think you have two options:

1) base64 of the value (so you don't have JSON in your url) and decode it on the onRouteMatched

2) If you don't mind losing the deep link to that page you can still save those values inside a temp JSON model and retrieve it on the onRouteMatched event 😉