ko.bindingHandlers.editMode =
{
update: function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext)
{
var newValueAccessor = ko.utils.unwrapObservable(valueAccessor());
var $element = $(element);
var viewModel = new someViewModel();
$element.append("<input type='text' data-bind='value: model.value' />");
ko.bindingHandlers.with.update(element, function() { return viewModel }, allBindingsAccessor, viewModel, bindingContext);
}
}
someViewModel 是一个视图模型,其中包含model.value
我要绑定到附加输入的属性(可观察)。with
但是当我为绑定调用更新时Uncaught TypeError: Cannot read property 'savedNodes' of undefined.
(knockout.js 调试构建)。我应该如何传递viewModel
towith.update
以使其获得与使用时相同的结果data-bind="with: new someViewModel()"
?谢谢!