简体   繁体   English

敲除绑定失败

[英]Knockout binding failed

Starting to pull my hair off! 开始脱掉我的头发! I am creating an object using Breeze (the metadata is coming from a web api server). 我正在使用Breeze创建一个对象(元数据来自web api服务器)。

The server side looks like this: 服务器端看起来像这样:

public class Product
{
    public int ProductId { get; set; }
    public String Name { get; set; }
    public String Description { get; set; }
}

On the client side, I create an entity using Breeze: 在客户端,我使用Breeze创建一个实体:

var product = ko.observable();
product(manager.createEntity('Product', {name:'', description:''}));

On the UI, I have the following: 在UI上,我有以下内容:

<div class="modal-body">
    <input type="text"" class="form-control"  data-bind="value: name" >
    <textarea class="form-control" data-bind="value: description"></textarea>
</div>

The problem is: knockout binds to the name no problem but not to the description! 问题是:淘汰赛绑定名称没有问题,但没有说明! Here is what I get in the console: 这是我在控制台中得到的:

Unable to process binding "value: function (){return description }" Message: description is not defined; 无法处理绑定“value:function(){return description}”消息:描述未定义;

What I don't get is: the product is properly created and contains all needed properties as shown in Chrome debug view: 我得不到的是: product已正确创建并包含Chrome调试视图中显示的所有必需属性:

在此输入图像描述

Make sure to bind to the proper context. 确保绑定到正确的上下文。 As @nemesv pointed out in the comments using a console.log() function directly inside of your textarea should be sufficient to find what properties are available. 正如@nemesv在评论中指出的,直接在textarea中使用console.log()函数应该足以找到可用的属性。

Given that you are using Durandal 2.0 you can also see what is available in the bound context using the console. 鉴于您使用的是Durandal 2.0,您还可以使用控制台查看绑定上下文中的可用内容。 Durandal's system logger actually outputs the currently bound context directly into the console. Durandal的系统记录器实际上将当前绑定的上下文直接输出到控制台。 It appears to show you which module was loaded and the context of that module. 它似乎向您显示加载了哪个模块以及该模块的上下文。

Binding views/patients/overview/index > Object { activate: function }

Expanding the object will show you what is currently available as well as any child properties. 扩展对象将显示当前可用的内容以及任何子属性。

你能尝试<textarea class =“form-control”data-bind =“value:description () ”> </ textarea>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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