Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Params does not parse arrays correctly #222

Closed
TheHans255 opened this issue May 10, 2016 · 2 comments
Closed

Params does not parse arrays correctly #222

TheHans255 opened this issue May 10, 2016 · 2 comments

Comments

@TheHans255
Copy link

I have a page in my application with this link:

<a data-bind="page-href: {path: '/graph', params: {id: data.entity.id, relationshipTypes: [3,4,6]}}">
    Test
</a>

that leads to a page like this one:

<article id="graph-page"
     data-bind="page: { 
        id: 'graph', 
        params: { 'id': '', 'relationshipTypes': [] } }"
     >
    <span data-bind="text: relationshipTypes"></span>
</article>

The link URL that is produced is serialized to

http://<domain>/#/graph?id=195975749&relationshipTypes%5B%5D=1&relationshipTypes%5B%5D=2&relationshipTypes%5B%5D=3&relationshipTypes%5B%5D=4&relationshipTypes%5B%5D=5&relationshipTypes%5B%5D=6

which becomes

http://<domain>/#/graph?id=195975749&relationshipTypes[]=1&relationshipTypes[]=2&relationshipTypes[]=3&relationshipTypes[]=4&relationshipTypes[]=5&relationshipTypes[]=6

This appears to be within jQuery's spec, and I would agree that it is a valid URL string to use.

However, PagerJS does not know how to parse this - relationshipTypes is left unbound in the page's view model. Would we be able to add the ability to parse these sorts of arguments into PagerJS?

For reference, this appears to be the function we would need to augment - it appears to do a simple Regex match that only recognizes primitive values as parameters:

var parseStringAsParameters = function (query) {
    var match,
        urlParams = {},
        search = /([^&=]+)=?([^&]*)/g;

    while (match = search.exec(query)) {
        urlParams[match[1]] = match[2];
    }
    return urlParams;
};
@TheHans255
Copy link
Author

This issue has been fixed in this fork:

https://github.com/rocketmonkeys/pagerjs

@DKhalil
Copy link
Collaborator

DKhalil commented May 3, 2017

I just merged the pullrequest from that repo!

@DKhalil DKhalil closed this as completed May 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants