trying to learn Knockoutjs.i have found a Knockoutjs custom binding related code but that is not very good.
<input data-bind="value: name" />
<hr/>
<div data-bind="fadeInText: name"></div>
ko.bindingHandlers.fadeInText = {
update: function(element, valueAccessor) {
$(element).hide();
ko.bindingHandlers.text.update(element, valueAccessor);
$(element).fadeIn();
}
};
var viewModel = {
name: ko.observable("Bob")
};
ko.applyBindings(viewModel);
i just do not understand when people go for custom binding ?
1) if possible tell me few situation when custom binding would be option?
2) if anyone see the code then they can understand custom binding fadeInText and viewModel has no relation but still it is working. how ?
3) if there would be multiple view model then how could i specify viewmodel name with binding name at the time of binding ?
jsfiddle link of the above code http://jsfiddle.net/rniemeyer/SmkpZ/
4) how to achieve the same output without custom binding ? was it possible ?
please answer my question point wise. thanks