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

withOnShow displays the observable function, not the value #122

Open
danielkennedy opened this issue Jun 26, 2013 · 4 comments
Open

withOnShow displays the observable function, not the value #122

danielkennedy opened this issue Jun 26, 2013 · 4 comments
Labels

Comments

@danielkennedy
Copy link

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();
});

@finnsson
Copy link
Owner

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.

@danielkennedy
Copy link
Author

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
Copy link
Author

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!

@finnsson
Copy link
Owner

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.

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

No branches or pull requests

2 participants