Skip to Content
0

How to pass array values(from multiComboBox) in routing

Feb 28 at 08:46 AM

66

avatar image

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Jun Wu Feb 28 at 02:10 PM
1

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

Show 2 Share
10 |10000 characters needed characters left characters exceeded

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

0

Hi,

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

Thanks,

Janani

0
Francesco Alborghetti Feb 28 at 09:48 AM
0

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));

capture.jpg (42.0 kB)
Show 3 Share
10 |10000 characters needed characters left characters exceeded

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

0

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?

0

Hi Francesco,

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

0
Emanuele Ricci Feb 28 at 09:21 AM
0

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 ;)

Share
10 |10000 characters needed characters left characters exceeded