havardhu
havardhu

Reputation: 3616

Breeze knockout value binding outputs a function

I'm using breeze with knockout against an odata endpoint and it gives some strange results. Hopefully I'm just missing something obvious, though.

This is my binding expression:

<input type="text" id="name" data-bind="value:organisation().name" />

where organisation is a ko.observable<myEntity> and myEntity has a property called name.

The value of the textbox is a function, which I suppose is the observable (although it might appear from reading the output that its actually a computed...?:

function f(){if(0<arguments.length){if("function"===typeof O)O.apply(d,arguments);else throw Error("Cannot write a value to a ko.computed unless you specify a 'write' option. If you wish to read the current value, don't pass any parameters.");return this}a.k.Jb(f);n&&k(!0);return q}

If I change the binding expression to value:organisation().name() then the correct values are displayed, but the two way binding is lost and changes won't be reflected.

Hopefully I've made a common mistake someone around here might point out!

Upvotes: 1

Views: 128

Answers (1)

Oskar Skuteli
Oskar Skuteli

Reputation: 658

If you bind it to organistion().name() then knockout works in "normal js expression" mode and two-way bindings won't work.

I don't realy know breeze, but it looks like your "name" observable is a property of an object which is a value of your "organization" observable. Try binding first to the outer with an "with" binding, and then to the inner one.

Like this:

<!-- ko with:organization -->
<input data-bind="value:name"></input>
<!-- /ko -->

Upvotes: 3

Related Questions