66Ton99
66Ton99

Reputation: 450

KnockoutJS - observable object doeasn't work

Is it possible to bind unexisting property in observable object? Because after I mapped it I don't see the result.

Example

Upvotes: 0

Views: 1958

Answers (1)

Niko
Niko

Reputation: 26730

I don't know a clean way, but you can do it like this:

<div data-bind="text: data().field1 ? data().field1() : ''"></div>​

Now (for some reason, not quite sure why) you need to explicitly communicate that the value of the observable has changed and the view should be updated:

ko.mapping.fromJS(Data, {}, model.data);
model.data.valueHasMutated();

http://jsfiddle.net/wF7xY/1/

Upvotes: 3

Related Questions