Testing the focus

by jcreamer898

HTML

<script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
<script src="http://documentcloud.github.com/backbone/backbone-min.js"></script>
<script src="http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.js"></script>
<script id="item-template" type="text/html">
    <input type="text" name="<%= model.name %>" />
</script>

<div id="showIt"></div>

CSS

ul {
    margin-left: 10px;
    padding-left: 10px;
    list-style-type: circle;
}

JavaScript

var item = Backbone.Model.extend({});
var itemsCollection = Backbone.Collection.extend({
    model: item
});

window.items = new itemsCollection();

var itemView = Backbone.View.extend({
    el: '$showIt',
    initialize: function(){
        this.template = _.template($("#item-template").html);   
        window.items.bind('add', this.render, this);
    },
    render: function(model){
        $(this.el).append(this.template(this.model.toJSON()));       
    }
});

$(function(){
    window.items.add({ name: 'Item 1' });
});