This file contains hidden or 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
| var View = Backbone.View.extend({ | |
| tagName: "ul", // Por padrão é gerado uma div, mas podemos colocar outra tag (por exemplo uma <ul>) | |
| className: "minha-ul", // Podemos adicioanar uma class ao elemento da view (<ul class='minha-ul'></ul>) | |
| id: "minha-ul", // Mesma coisa do className só que para adicionar um id (<ul id='minha-ul'></ul>) | |
| el: "#principal", // Se o elemento já esta renderizado na página, podemos passar o el, assim ele não cria um elemento novo | |
| }); |
This file contains hidden or 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
| var View = Backbone.View.extend({ | |
| template: _.template("<h1> <%= title %> </h1>"), // O template espera title como variavel | |
| render: function() { | |
| this.$el.html(this.template(this.model.attributes)); // Passando o title para o template | |
| return this; | |
| } | |
| }); | |
| var view = new View({ |
This file contains hidden or 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
| var View = Backbone.View.extend({ | |
| template: _.template("<h1> Título da View </h1>"), | |
| render: function() { | |
| this.$el.html(this.template()); | |
| return this; | |
| } | |
| }); |
This file contains hidden or 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
| var View = Backbone.View.extend({ | |
| events: { | |
| "click .item": "clicked" | |
| }, | |
| clicked: function() { | |
| console.log("Item clicado"); | |
| } | |
| }); |
This file contains hidden or 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
| // View = gist 6201b9d1d2d74c673dd0 | |
| var view = new View(); | |
| view.render(); // Adicionando o conteúdo na view | |
| $("div").html(view.el); // Adiciona a view no DOM |
This file contains hidden or 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
| var View = Backbone.View.extend({ | |
| render: function() { | |
| this.$el.html("View exemplo"); | |
| return this; | |
| } | |
| }); |
NewerOlder