Knockout-jQueryUI

Fork me on GitHub

Buttonset.html

Themable button sets.

Parameters

For each of the widget's options the binding has a corresponding option with the same name. These can be set to static values, or bound either to normal or to observable properties of the viewmodel.

For each of the widget's events the binding has a corresponding option with the same name. These can be set to functions. When invoked the value of the this keyword evaluates to the viewmodel.

refreshOn

Should be bound to one of the viewmodel's observables. Every time that observable changes, the widget is refreshed (it's refresh method is invoked).

widget

Should be bound to one of the viewmodel's writeable observables. The binding will write a jQuery object containing the binding's DOM element into it. The primary use for this option is to invoke the widget's methods on the element.

Example

HTML

<div data-bind="foreach: items, buttonset: { refreshOn: items }">
  <input type="checkbox" data-bind="attr: { id: id }" />
  <label data-bind="attr: { 'for': id }, text: label"></label>
</div>
<p>
  <button data-bind="click: onAdd">Add</button>
</p>

JavaScript

var counter = 2;
var ItemViewModel = function(id) {
  this.id = 'chk' + id.toString();
  this.label = id.toString();
};
var ViewModel = function () {
  this.items = ko.observableArray([
    new ItemViewModel(1),
    new ItemViewModel(2)
  ]);
};
ViewModel.prototype.onAdd = function() {
  this.items.push(new ItemViewModel((++counter)));
};

Result