Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
withOnShow not updating on navigation #143
I'm using withOnShow to bind a viewmodel based on a wildcard id.
The showView will use pager.getActivePage().currentId to get the current id and request the corresponding viewmodel data.
It works fine on the first page load (/view/1) but if I click on a link to /view/2 the viewModel is not updated, the first one is still used. But if i point my browser to /view/2 directly the correct viewModel loads.
Have I missed anything or can I force pagerjs to refresh to the new viewModel?
I have logged the viewModel returned by the showView function and it will return the correct vm on link navigation.
I don't want to step on Oscar's toes, but I'm pretty sure that this happens because the page attempts to rebind the second time you view it as the source is not being loaded in, but you are changing the viewmodel with the withOnShow parameter.
You could get around this by modifying the page to also use sourceOnShow or in my case I've added some code that copies the page contents into another field and then if this specific case is matched I replace the contents before it's bound again (not the best approach possibly, but it works).
This broke at exactly
on knockoutjs. In pagerjs,
I'm continuing to debug this. At the moment, pagerjs is virtually unusable for me, so let me know how I can be of more assistance.
(@finnsson I hate to tag you, but you haven't responded to this issue yet and it has been 3 months, so I am just making sure you didn't miss it. Sorry to be annoying!!!)
Instead of applying the bindings more than once, can we
I think that will result in sourceOnShow implementations breaking. As a quick fix and until there is a better solution you can have a look at the code that I've implemented.
At the top of p.init but after the declaration of m insert:
and then in the loadWithOnShow sub insert:
and move the with onShowLoaded to the bottom so that it looks like:
ps. I consider this to be a bit nasty and I'm looking into a better way to do it. Alternatively you could implement sourceOnShow for the page. I'll post back if I come up with a better solution or let me know if you come up with something good.