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.

47 lines
1.0 KiB

  1. define(function (require) {
  2. var model = {};
  3. model.Model = function () {
  4. this.items = [];
  5. };
  6. model.Model.prototype.load = function (items) {
  7. this.items = items;
  8. };
  9. model.Model.prototype.create = function (title) {
  10. title = title || '';
  11. var newItem = {
  12. id: new Date().getTime(),
  13. title: title.trim(),
  14. completed: 0
  15. };
  16. this.items.push(newItem);
  17. return newItem;
  18. };
  19. model.Model.prototype.remove = function (id) {
  20. for (var i = 0; i < this.items.length; i++) {
  21. if (this.items[i].id == id) {
  22. this.items.splice(i, 1);
  23. break;
  24. }
  25. }
  26. };
  27. model.Model.prototype.update = function (id, updateData) {
  28. for (var i = 0; i < this.items.length; i++) {
  29. if (this.items[i].id == id) {
  30. for (var x in updateData) {
  31. this.items[i][x] = updateData[x];
  32. }
  33. }
  34. }
  35. };
  36. return model;
  37. });