Guest User

Untitled

a guest
Feb 19th, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. const PostModel = Backbone.Model.extend({
  2. defaults: {
  3. title:'Titulo Não definido',
  4. content: 'Nada para mostrar'
  5. },
  6. initialize: function () {
  7. console.log(`My name is ${this.attributes.title}`)
  8. },
  9. parse: function (response) {
  10. return response;
  11. },
  12. toJSON: function () {
  13. return _.clone(this.attributes)
  14. }
  15. })
  16.  
  17.  
  18. const PostView = Backbone.View.extend({
  19. el:'#app',
  20. tagName: 'article',
  21. className: 'posts-article',
  22. id: 'my-first-article',
  23. initialize: function () {
  24. this.model = new PostModel({
  25. title: 'Super Post Sobre Backbone',
  26. content: "Um texto super legal sobre as maravinhas do Backbone.js!"
  27. })
  28.  
  29. this.render()
  30. },
  31. template: _.template("<h2><%= title %></h2><p><%= content %></p>"),
  32. render: function () {
  33. let html = this.template(this.model.toJSON())
  34. this.$el.html(html)
  35. }
  36. })
  37.  
  38. $(document).ready( function () {
  39. const post = new PostView()
  40. })
Add Comment
Please, Sign In to add comment