0
我想我的第一個自定義綁定在淘汰賽,但不能似乎得到它的工作。我從http://knockoutjs.com/documentation/custom-bindings.html得到了這個樣本。自定義綁定不會觸發?
腳本
ko.bindingHandlers.slideVisible = {
update: function (element, valueAccessor, allBindings) {
debugger;
// First get the latest data that we're bound to
var value = valueAccessor();
// Next, whether or not the supplied model property is observable, get its current value
var valueUnwrapped = ko.unwrap(value);
// Grab some more data from another binding property
var duration = allBindings.get('slideDuration') || 400; // 400ms is default duration unless otherwise specified
// Now manipulate the DOM element
if (valueUnwrapped == true) $(element).slideDown(duration); // Make the element visible
else $(element).slideUp(duration); // Make the element invisible
}
};
HTML
<div data-bind="slideVisible: giftWrap, slideDuration:600">You have selected the option</div>
<label>
<input type="checkbox" data-bind="checked: giftWrap" />Gift wrap</label>
<script type="text/javascript">
var viewModel = {
giftWrap: ko.observable(true)
};
ko.applyBindings(viewModel);
</script>
的jsfiddle鏈接:http://jsfiddle.net/dingen2010/2gpL6/1/