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

sending wildcards to the viewmodel #52

Closed
gilesbradshaw opened this issue Nov 2, 2012 · 6 comments
Closed

sending wildcards to the viewmodel #52

gilesbradshaw opened this issue Nov 2, 2012 · 6 comments
Milestone

Comments

@gilesbradshaw
Copy link
Collaborator

@gilesbradshaw gilesbradshaw commented Nov 2, 2012

More of a suggestion than a bug but would be very interested to know if this might be possible.

I'd like to be able to have an href like this parent/x/child/y/grandchild/z
such that x y and z get bound to values in the view model - in the same manner as URI parameters can be

and pages set up like this

<div data-bind = "page : {id:'parent'}">
    <div data-bind = "page : {id:'?', wildcard:pickparent}">      
        <!-- ko with: parent -->
            <div data-bind = "page : {id:'child'}">
                <div data-bind = "page : {id:'?', wildcard:pickchild}">      
                    <!-- ko with: child -->
                          --- the same for grandchild

                     <!--  /ko -->
                  <div>
            </div>            
        <!--  /ko -->
    <div>
</div>
@gilesbradshaw
Copy link
Collaborator Author

@gilesbradshaw gilesbradshaw commented Nov 2, 2012

ok this is how I have implemented it I've called it nameParam so you do nameParam:'observablename'

I've put this at the start of your setParams function

if (this.pageRoute) {
            var nameParam = this.val('nameParam') || false;
            if (nameParam) {
                if (this.ctx[nameParam]) { // set observable ...
                    this.ctx[nameParam](this.pageRoute.name);
                } else { // ... or create observable
                    this.ctx[nameParam] = ko.observable(this.pageRoute.name);
                }
            }

        }
@finnsson
Copy link
Owner

@finnsson finnsson commented Nov 2, 2012

Sounds excellent. I can see how this can be really useful. Do you got a fork that I can merge, are you interested in sending a pull request or should I copy the above code?

@gilesbradshaw
Copy link
Collaborator Author

@gilesbradshaw gilesbradshaw commented Nov 3, 2012

Hi - glad you like it - I will fork and do a pull request but if I haven't and you want to incorporate it go ahead any how.

@gilesbradshaw
Copy link
Collaborator Author

@gilesbradshaw gilesbradshaw commented Nov 3, 2012

mmm forked it but then when I try and clone repository to my PC I get

C:\Program Files (x86)\Git\bin\git.exe clone -v --recurse-submodules --progress "git@github.com:GilesBradshaw/pagerjs.git" "C:/Users/giles/Documents/Visual Studio 2012/Projects/gbpagerjs"
Cloning into 'C:/Users/giles/Documents/Visual Studio 2012/Projects/gbpagerjs'...
remote: Total 1388 (delta 827), reused 1155 (delta 594)�[K
fatal: cannot create directory at 'demo/escaped_fragment/params/search?product=tv&price=200': Invalid argument
Done

Maybe you could just copy my code into your project if you wish to.

cheers

g

@finnsson finnsson closed this in 0d45ad5 Nov 3, 2012
@finnsson
Copy link
Owner

@finnsson finnsson commented Nov 3, 2012

I updated the repo so it can be cloned from windows and fixed the nameParam-config.

You can read about binding_wildcard_to_observable.

@gilesbradshaw
Copy link
Collaborator Author

@gilesbradshaw gilesbradshaw commented Nov 4, 2012

brilliant! Thanks for that :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.