Leroy Meijer
Leroy Meijer

Reputation: 1197

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

Upvotes: 5

Views: 1211

Answers (2)

PW Kad
PW Kad

Reputation: 14995

Change it to currentCustomer().name and that should work provided that Name is a property on the currentCustomer entity.

Upvotes: 0

DeeDub
DeeDub

Reputation: 1662

Have you tried using 'with'?

<div data-bind='with:currentCustomer'>
<input data-bind="value: Name/Name()" />
</div>

Upvotes: 3

Related Questions