Masriyah
Masriyah

Reputation: 2525

Uncaught Error: Unable to parse bindings Knockout

I am not sure why it is not able to parse the bindings - each of them does contain content. This is the error message:

Uncaught Exception (js): Uncaught Error: Unable to parse bindings.
Message: ReferenceError: Users is not defined;
Bindings value: template: { name: 'grid', foreach: Users}

View:

<div data-bind="foreach: RoleTypes">
            <h3><!--ko text: RoleName--><!--/ko--> (<!--ko text: UserCount--><!--/ko-->)</h3>
            <div id="gridView"  data-bind="template: { name: 'grid', foreach: Users}">
                <section id="Images">
                    <section id="users"></section>
                </section>
            </div>
        </div>

Javascript:

var getRoles = function () {
        Ajax.Get({
            Url: ...,
            DataToSubmit: {id: properties.Id },
            DataType: "json",
            OnSuccess: function (roleData, status, jqXHR) {
                // bind role types
                bindModel(roleData);

                Ajax.Get({
                    Url: ...,
                    DataToSubmit: { pageNumber: 1, id: properties.Id },
                    DataType: "json",
                    OnSuccess: function (userData, status, jqXHR) {

                    }
                });
            }
        });
    };

I am not sure what other parts of my javascript to share to help with this but please let me know.

Upvotes: 0

Views: 1854

Answers (2)

ebohlman
ebohlman

Reputation: 15003

The error message means that one or more of the objects in your ViewModel's RoleTypes array doesn't have a property called Users. Without seeing the code that defines your VM I can only guess why, but is it possible that Users is a top-level property rather than a sub-property of each RoleType? If so, then you need to replace Users with $root.Users so Knockout knows where to look for it.

Update based on comments

Each element of RoleTypes needs to have an observableArray property called Users which then gets populated with the users for a particular role. Once you do that, you don't have to qualify Users with $root because it's a property of the current iteration element.

Upvotes: 1

Daniel A. White
Daniel A. White

Reputation: 191058

Put foreach in quotes in your data-bind attribute. Some browsers are picky.

Upvotes: 1

Related Questions