hide some details using router.navigate in javascr

2020-04-17 03:08发布

问题:

I need to post some data to server in ajax call. I am binding data into json format and posting it to server:

var BookMarkData = JSON.stringify(postData);
self.app.router.navigate('#hotels/' + BookMarkData, true);

I want to show only 4 elements from postdata JSONArray in the url. But I need to pass entire data to server.

fetchResults: function(PostData) {
  var self = this;
  var postData = JSON.parse(hashedPostData);
  .......
}

How can I pass entire information to fetch results by hiding some information in the url?

回答1:

If you need to show only 4 elements from postdata I assume that it is an array. Use slice:

var bookMarkData = JSON.stringify(postData),
    routeData = JSON.stringify(postData.slice(0, 4))
self.app.router.navigate('#hotels/' + bookMarkData, true);

bookMarkData still holds the the whole array.