A binding provider for knockoutjs bind data without using data-bind on views.
JavaScript
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
README.md
example.css
example.js
index.html
knockout-jqueryBindingProvider.js

README.md

Knockout jQuery binding provider.

A custom binding provider for Knockout.js that allows you to define bindings using jquery selectors instead of filling your view elements with complex data-bind attributes.

DEMO: http://vic.github.com/knockout-jqueryBindingProvider

Dependencies

<script src="jquery.js"></script>
<script src="knockout.js"></script>
<script src="knockout-jqueryBindingProvider.js"></script>

Usage

  //  having a view model like this
  var viewModel = {
    firstName: ko.observable(),
    lastName: ko.observable()
  };
  viewModel.fullName = ko.computed({
    owner: viewModel,
    read: function() {
      return this.firstName() + ' ' + this.lastName();
    }
  });

  // you can bind its properties with
  $('.main').ko(viewModel, {
      'span.full-name': function(vm){
        return { text: vm.fullName };
      },
   
      '.first-name input': function(vm){
        return {
          value: vm.firstName,
          valueUpdate: 'afterkeydown'
        };
      },

      '.last-name input': function(vm){
        return {
          value: vm.lastName,
          valueUpdate: 'afterkeydown'
        };
      }
  });