with
旨在与对象一起使用。所以它对真实性进行了简单的检查,认为零是错误的。您可以通过将数字转换为字符串来解决此问题:http: //jsfiddle.net/rG5Xw/11/
编辑:这是with
基于我的替代品withlight
,它不检查值(例如:http: //jsfiddle.net/mbest/rG5Xw/12/):
ko.bindingHandlers['mywith'] = {
'init': function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
var bindingValue = ko.utils.unwrapObservable(valueAccessor());
var innerContext = bindingContext['createChildContext'](bindingValue);
ko.applyBindingsToDescendants(innerContext, element);
return { 'controlsDescendantBindings': true };
}
};
ko.virtualElements.allowedBindings.mywith = true;