not really known
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.3 KiB

  1. define(function (require) {
  2. var view = {};
  3. view.View = function () {
  4. this.template =
  5. '<li data-id="{{id}}" class="{{completed}}" draggable="true" ondragstart="drag(event)" ondragover="allowDrop(event)" ondrop="drop(event)">' +
  6. '<div class="view">' +
  7. '<input class="toggle" type="checkbox" {{checked}}>' +
  8. '<label>{{title}}</label>' +
  9. '<button class="remove"></button>' +
  10. '</div>' +
  11. '</li>';
  12. };
  13. // Create a string of HTML <li> elements inside with the given
  14. // items.
  15. view.View.prototype.show = function (items) {
  16. var i, l;
  17. var view = '';
  18. for (i = 0, l = items.length; i < l; i++) {
  19. var template = this.template;
  20. var completed = '';
  21. var checked = '';
  22. if (items[i].completed === 1) {
  23. completed = 'completed';
  24. checked = 'checked';
  25. }
  26. template = template.replace('{{id}}', items[i].id);
  27. template = template.replace('{{title}}', items[i].title);
  28. template = template.replace('{{completed}}', completed);
  29. template = template.replace('{{checked}}', checked);
  30. view = view + template;
  31. }
  32. return view;
  33. };
  34. return view;
  35. });