JSFiddle - React, Tailwind, and code Playground

by jelatin

HTML

<script src="http://underscorejs.org/underscore-min.js"></script>
<script src="http://backbonejs.org/backbone-min.js"></script>
<body></body>

JavaScript

(function() {
    window.App = {
        Models: {},
        Views: {},
        Collections: {}
    };
             
    
    App.Models.Person = Backbone.Model.extend({
        defaults: {
            name: 'John',
            phone: '555-555-5555'
        }
    });
    
    App.Views.Person = Backbone.View.extend({
        tagName: 'li',
        
        template: _.template("<%= name %> -- <%= phone %>"),
        
        render: function(){
            var template = this.template( this.model.toJSON() );
            
            this.$el.html( template );
            
            return this;
        }
    });
    
    App.Collections.People = Backbone.Collection.extend({
        model: App.Models.Person 
    });
    
    App.Views.People = Backbone.View.extend({
        tagName: 'ul',
        
        add: function(person){
            var personView = new App.Views.Person({ model: person });
            
            this.$el.append( personView.render().el );
            
            return this;
        },
        
        render: function() {
            this.collection.each(this.add, this);
            
            return this;
        }
    });
    
    
    
})();

var peeps = [ { name: 'Mary' }, { name: 'David' }, { name: 'Tiffany' } ];

var people = new App.Collections.People(peeps);

var peopleView = new App.Views.People({ collection: people });

peopleView.render().$el.appendTo('body');