rush:js;">
ko.bindingHandlers.yourBindingName = {
init: function(element,valueAccessor,allBindings,viewmodel,bindingContext) {
// This will be called when the binding is first applied to an element
// Set up any initial state,event handlers,etc. here
},update: function(element,bindingContext) {
// This will be called once when the binding is first applied to an element,// and again whenever any observables/computeds that are accessed change
// Update the DOM element based on the supplied values here.
}
};
rush:java;">
ko.bindingHandlers.slideVisible = {
update: function(element,allBindings) {
// 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
}
};
rush:js;">
ko.bindingHandlers.slideVisible = {
init: function(element,valueAccessor) {
var value = ko.unwrap(valueAccessor()); // Get the current value of the current property we're bound to
$(element).toggle(value); // jQuery will hide/show the element depending on whether "value" or true or false
},allBindings) {
// Leave as before
}
};