pagerjs icon indicating copy to clipboard operation
pagerjs copied to clipboard

withOnShow displays the observable function, not the value

Open danielkennedy opened this issue 12 years ago • 4 comments

Hi,

I'm going crazy trying to figure this out... withOnShow is lazy-binding, but I'm not getting the value of the observable within the page, but rather the function prototype of the observable, as in:

function c(){if(0

-- Markup --

window.bindNewModel = function (js) { return function (callback, page) { require(['models/' + js], function (model) { callback(model); }); }; };

-- View --

Feature Codes

-- View Model -- define(["js/knockout-2.1.0.js"], function (ko) { function FeatureCodesModel(gau) { var self = this; self.featurecodes = ko.observable(''); } return new FeatureCodesModel(); });

danielkennedy avatar Jun 26 '13 02:06 danielkennedy

Hi,

could you post a jsfiddle/jsbin-example that illustrates your problem? It makes it easier for me to track down the exact problem. I could not see any obvious problem when glancing at your code.

You could take a look at example_1 - a small example template/boilerplate I've put together.

In index.html I got the line

<div data-bind="page: {id: 'product', sourceOnShow: 'page/product.html', withOnShow: requireVM('product')}"></div>

and requireVM is defined as

window.requireVM = function (moduleName) {
    return function (callback) {
        require([moduleName], function (mod) {
            callback(mod);
        });
    };
};

while the module can be found at product.

One final note is that you might have encountered a bug if withOnShow is bound to an observable. I have to double-check that I'm not just taking its raw value but actually unwrapping the observable first. I'll get back to you on that one.

finnsson avatar Jun 26 '13 06:06 finnsson

I can't seem to get pagerjs working in a fiddle at all, unfortunately. It's entirely my fault, as I've not worked much with fsFiddle...

It occurs that your final paragraph could be accurate, though. I'm testing more now, and will provide an update.

danielkennedy avatar Jun 26 '13 16:06 danielkennedy

Confirmed that the "you might have encountered a bug" is the problem. When I used your example_1 demo, but modified the div (page container) from:

to

it all fell apart, as in:

Uncaught Error: Unable to parse bindings. Message: ReferenceError: id is not defined; Bindings value: page: {id: id, title: title, scrollToTop: true, sourceOnShow: 'page/' + id + '.html', sourceCache: true, role: 'start', withOnShow: requireVM(id)}

I'm happy to help with a pull request, if you think the change is too involved to warrant fixing at this time. Please let me know. Thanks!

danielkennedy avatar Jun 26 '13 20:06 danielkennedy

I might have time to look at this later today (around 1800 UTC), but you are welcome to help out with a pull request.

Some of your html got stripped in the comments field (you need to indent all code with 4 blanks) so it is a bit difficult for me to see how you changed the code.

finnsson avatar Jun 27 '13 07:06 finnsson