Backbone & Things Example

by sehsarah

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://dundalek.com/bindem/src/bindem.js"></script>
<div class="liveExample">   
    <input type="text" class="yourName" placeholder="What's your name?" /><hr>
    <h2>Hello <span class="yourName"></span>!</h2>
</div>

JavaScript

var View = Backbone.View.extend({
    modelBindings: {
        yourName: {
            text: 'span.yourName',
            value: {
                selector: 'input.yourName',
                event: 'keyup'
            }
        }
    },
    initialize: function() {
        Bindem.on.call(this, this.modelBindings, {
            initialize: true
        });
    }
});

var personModel = new Backbone.Model({
    yourName: 'John'
});

var view = new View({
    model: personModel,
    el: $('.liveExample')
});