Skip to content

Access to Page in withOnShow handler #27

@Shildrak

Description

@Shildrak

First, thanks for creating a really nice library!

It would be nice to have access to the Page object when dynamically fetching viewmodels in "withOnShow". I modified the source for withOnShow to pass "this", just like you are currently doing for sourceOnShow:
I replaced
572 - }, this));
572 + }, this), this);

This allow me to retrieve specific data for my views based on the route, eg

http://domain.name.com/order/56

 <div data-bind="page: {id: '?', withOnShow: MyNamespace.Order.GetModel()}"></div>

MyNamespace.Order = {
    GetModel: function () {
        return function (callback, page) {
            $.getJSON('/api/orders/' + page.currentId, function (data) {
                var viewModel = new MyNamespace.Order.ViewModel(data);
                callback(viewModel);
            });
        };
    }
};

Off course, ability to use wildcards would be even better, to say something like:

 <div data-bind="page: {id: '?', withOnShow: MyNamespace.Order.GetModel({1})}"></div>

But I don't think this is an easy addition? However, I hope you will consider adding the page parameter as described above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions