开始扯掉我的头发! 我正在使用 Breeze 创建一个对象(元数据来自 Web API 服务器)。
服务器端看起来像这样:
public class Product
{
public int ProductId { get; set; }
public String Name { get; set; }
public String Description { get; set; }
}
在客户端,我使用 Breeze 创建了一个实体:
var product = ko.observable();
product(manager.createEntity('Product', {name:'', description:''}));
在 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>
问题是:knockout 绑定(bind)到名称没有问题但没有绑定(bind)到描述!这是我在控制台中得到的:
Unable to process binding "value: function (){return description }" Message: description is not defined;
我没有得到的是:product
已正确创建并包含所有需要的属性,如 Chrome 调试 View 所示:
最佳答案
确保绑定(bind)到正确的上下文。正如 @nemesv 在评论中指出的那样,直接在文本区域内使用 console.log() 函数应该足以找到可用的属性。
鉴于您使用的是 Durandal 2.0,您还可以使用控制台查看绑定(bind)上下文中可用的内容。 Durandal 的系统记录器实际上将当前绑定(bind)的上下文直接输出到控制台。它似乎向您显示加载了哪个模块以及该模块的上下文。
Binding views/patients/overview/index > Object { activate: function }
展开对象将显示当前可用的内容以及任何子属性。
关于javascript - knockout 绑定(bind)失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20847802/