Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const PostModel = Backbone.Model.extend({
- defaults: {
- title:'Titulo Não definido',
- content: 'Nada para mostrar'
- },
- initialize: function () {
- console.log(`My name is ${this.attributes.title}`)
- },
- parse: function (response) {
- return response;
- },
- toJSON: function () {
- return _.clone(this.attributes)
- }
- })
- const PostView = Backbone.View.extend({
- el:'#app',
- tagName: 'article',
- className: 'posts-article',
- id: 'my-first-article',
- initialize: function () {
- this.model = new PostModel({
- title: 'Super Post Sobre Backbone',
- content: "Um texto super legal sobre as maravinhas do Backbone.js!"
- })
- this.render()
- },
- template: _.template("<h2><%= title %></h2><p><%= content %></p>"),
- render: function () {
- let html = this.template(this.model.toJSON())
- this.$el.html(html)
- }
- })
- $(document).ready( function () {
- const post = new PostView()
- })
Add Comment
Please, Sign In to add comment