简体   繁体   中英

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

Have you tried using 'with'?

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

将其更改为 currentCustomer().name 并且如果 Name 是 currentCustomer 实体上的一个属性,那么它应该可以工作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM