Question

So in my PhoneJS web app, I have a dxList widget, with checkboxes on each item. I want to be able to select multiple items, and then do something with them. I'm trying to bind the 'checked' binding to an observable, but I get an 'undefined' error.

Here's the code for the dxTemplate for the list

<div data-options="dxTemplate:{name:'item'}">
    <span data-bind="text: $data.information"></span>
    <div data-bind="dxCheckBox: { checked: check_boxes }"></div>
</div>

The problem is that check_boxes is in the viewModel, not the item array. I need to access values in the viewModel. I've tried viewModel.check_boxes, but with no success.

Here's the js code:

AppNamespace.otherView = function (params) {
    var viewModel = {
        my_list: [
            {
                key: 'Group 1',
                items: [
                    { information: 'Test 1' },
                    { information: 'Test 2'},
                    { information: 'Test 3' }
                ]
            }
        ],
        check_boxes: ko.observable(false),
        //...etc

Has anyone had any experience with this, and is there a solution?

Thanks!

Was it helpful?

Solution

Knockout provides special properties to access parent binding contexts. In your case both $parent and $root should work.

More on this topic in Knockout docs: Binding context.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top