无法使用 KnockoutJS 进行数据绑定

Ler*_*jer 5 javascript knockout.js breeze

我目前正在使用 DurandalJS、BreezeJS 和 KnockoutJS 开发一个应用程序。

一切都很好,但最简单的事情(我相信),我无法让它工作。

在我的 Viewmodel 中,我有一个 currentCustomer,它是一个 ko.observable。通过微风我得到了客户!currentCustomer(data.results[0].Customer());这一切正常。如果我使用谷歌浏览器检查,我会看到该对象充满了 currentCustomer。

我想要的是以下内容:我有一个输入字段和一个值数据绑定,我试图将 currentCustomer 的名称绑定到这个输入。但我无法让它发挥作用。有效的是这样的:

 <input data-bind="value: currentCustomer()" />
Run Code Online (Sandbox Code Playgroud)

但是在输入字段中它只说 [Object object] 所以在 currentCustomer 中肯定有一些东西(这是)。

这是我尝试过但没有奏效的方法:

<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()" />
Run Code Online (Sandbox Code Playgroud)

这是一个屏幕截图,因此您可以看到值在视图中!

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

TNC*_*key 3

您尝试过使用“with”吗?

<div data-bind='with:currentCustomer'>
<input data-bind="value: Name/Name()" />
</div>
Run Code Online (Sandbox Code Playgroud)