1
votes

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!

1
Can you post here your "organisation" model code?TSV
Not really. I have an interface for it, but that's just typescript stuff that doesn't really matter runtime. The model itself is created by Breeze, as I understand ithavardhu
Need a repro. You should be able to create a mini version, a one entity version of your model ... just the Organization entity for example ... that produces this behavior. The metadata is key. Would be great as a jsfiddle or plunker.Ward

1 Answers

3
votes

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 -->