todos.js 772 B

123456789101112131415161718192021222324252627282930
  1. $(function () {
  2. // Create a model class.
  3. const TodoItem = Backbone.Model.extend({});
  4. // Create a model instance.
  5. const todoItem = new TodoItem({
  6. description: "Remember the milk",
  7. status: "incomplete",
  8. id: 1,
  9. });
  10. // Manipulate attributes.
  11. const description = todoItem.get('description');
  12. todoItem.set('status', 'complete');
  13. // Save to the server: needs some configuration.
  14. // todoItem.save();
  15. // Create a view class.
  16. const TodoView = Backbone.View.extend({
  17. render: function () {
  18. const html = '<h3>' + this.model.get('description') + '</h3>';
  19. $(this.el).html(html);
  20. },
  21. });
  22. // Create a view instance.
  23. const todoView = new TodoView({ model: todoItem });
  24. todoView.render();
  25. $('#app').html(todoView.el);
  26. });