Search code examples
knockout.jsknockout-mapping-plugin

Knockout doesn't apply binding for given viewmodel


Could someone explain me why this works

    self.test("some data");
    <span data-bind="text:test"></span>

and this not work

    self.test(ko.mapping.fromJS({ complex: "object"}));
    <span data-bind="text:test.complex"></span>

Solution

  • test is an observable, so you have to unwrap it to access the internal properties.

    self.test(ko.mapping.fromJS({ complex: "object"}));
    <span data-bind="text:test().complex"></span>