Skip to content

Instantly share code, notes, and snippets.

@jparbros
Created February 11, 2012 04:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jparbros/1796180 to your computer and use it in GitHub Desktop.
Save jparbros/1796180 to your computer and use it in GitHub Desktop.
backbone.js ejemplo
window.Representante = Backbone.Model.extend({})
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;
}
});
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