Creating a custom knockoutJS binding for a simple jQuery plugin

Is there a general approach, or at least a set of steps, that a KnockoutJS developer should take to create a binding for simple jquery plugins.

For example, if a plugin runs like this in the "common code":

$('#tag1').tagsInput({ // my parameters here });

What would be the simplest KO user binding for this plugin?

+7
source share
1 answer

Here is a general way, for example, for a jQuery button:

 ko.bindingHandlers.jqButton = { init: function(element, valueAccessor) { var options = valueAccessor() || {}; $(element).button(options); } }; <button data-bind="click: greet, jqButton: { icons: { primary: 'ui-icon-gear' } }">Test</button> 

Read this article for some best practices: http://www.knockmeout.net/2011/07/another-look-at-custom-bindings-for.html

+6
source

All Articles