jQuery UI accordion

https://groups.google.com/d/topic/knockoutjs/h97sy04PK10/discussion

HTML

<script src="http://cloud.github.com/downloads/SteveSanderson/knockout/knockout-1.3.0beta.debug.js"></script>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/base/jquery-ui.css">
<div data-bind="foreach: items, accordion: {}">
    <h3>
        <a href="#" data-bind="text: id"></a>
    </h3>
    <div>    
        <span data-bind="text: name"></span>
        <div data-bind="foreach: items, accordion: {}">
            <h3>
                <a href="#" data-bind="text: id"></a>
            </h3>
            <div data-bind="text: name">
            </div> 
        </div>
        <button data-bind="click: add">Add Sub Item</button>
    </div> 
</div>
<button data-bind="click: add">Add Item</button>
<hr/>

JavaScript

ko.bindingHandlers.accordion = {
    init: function(element, valueAccessor) {
        var options = valueAccessor() || {};
        setTimeout(function() {
            $(element).accordion(options);
        }, 0);

        //handle disposal (if KO removes by the template binding)
        ko.utils.domNodeDisposal.addDisposeCallback(element, function() {
            $(element).accordion("destroy");
        });
    },
    update: function(element, valueAccessor) {
        var options = valueAccessor() || {};
        $(element).accordion("destroy").accordion(options);
    }
}

function Item(id, name, subItems) {
    var self = this;

    //properties
    this.id = ko.observable(id);
    this.name = ko.observable(name);
    this.items = ko.observableArray(subItems);

    //actions
    this.add = function() {
        self.items.push(new Item(4, "bar"));
    };
}

var viewModel = {
    items: ko.observableArray([
        new Item(1, "one", 
            [
             new Item(11, "one-one"), 
             new Item(12, "one-two")
            ]),
        new Item(2, "two", []), 
        new Item(3, "three", []) 
    ]),
        
    add: function() {
        viewModel.items.push(new Item(4, "foo"));
    }
};

ko.applyBindings(viewModel);