Created
February 11, 2012 04:32
-
-
Save jparbros/1796180 to your computer and use it in GitHub Desktop.
backbone.js ejemplo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.Representante = Backbone.Model.extend({}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.RepresentanteView = Backbone.View.extend({ | |
initialize: function() { | |
this.template = _.template($('#representante-template').html()); | |
_.bindAll(this,'render'); | |
this.model.bind('change', this.render); | |
}, | |
render: function() { | |
$('.representante').html(this.template(this.model.toJSON())); | |
return this; | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.Directorio = Backbone.Router.extend({ | |
routes: { | |
'representante/:lugar/:posicion' : 'representante' | |
}, | |
initialize: function() { | |
}, | |
representante: function(lugar, posicion) { | |
representante = new Representante(); | |
representante.url = '/representantes/'+ lugar + '?posicion='+ posicion; | |
representante.fetch(); | |
representanteVista = new RepresentanteView({model: representante}); | |
if(representante.get('name') == undefined) { | |
$('.representante').html('La información no se enuentra disponible'); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment