Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't get my data-binding with knockoutJS to work

I'm currently working on an application with DurandalJS, BreezeJS and KnockoutJS.

Everything goes fine but the most simple thing (I believe), I can't get it to work.

In my Viewmodel I have a currentCustomer which is a ko.observable. Via Breeze I get the customer! currentCustomer(data.results[0].Customer()); This is all working fine. If I check with Google Chrome I see the object is filled with the currentCustomer.

What I want is the following: I have an inputfield and with a value data-bind I'm trying to bind the Name of the currentCustomer to this input. But I can't get this to work. What works is this:

 <input data-bind="value: currentCustomer()" />

But in the input field it only says [Object object] So there is definitely something in the currentCustomer (which is).

This is what I tried but didn't work:

<input data-bind="value: currentCustomer().Name()" />
<input data-bind="value: currentCustomer().Name" />
<input data-bind="value: currentCustomer.Name()" />
<input data-bind="value: currentCustomer.Name" />
<input data-bind="value: currentCustomer()._latestValue().Name()" />
<input data-bind="value: currentCustomer()._latestValue.Name()" />

Here is a screenshot so you can see the values are in the view!

http://s22.postimg.org/62m21nnsx/problem_data_bind.png

like image 658
Leroy Meijer Avatar asked Oct 22 '22 10:10

Leroy Meijer


1 Answers

Have you tried using 'with'?

<div data-bind='with:currentCustomer'>
<input data-bind="value: Name/Name()" />
</div>
like image 82
DeeDub Avatar answered Oct 24 '22 03:10

DeeDub