PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/examples/todos-requirejs-4/models/todo.js

https://github.com/pmichelberger/backbone
JavaScript | 34 lines | 19 code | 10 blank | 5 comment | 0 complexity | 1bca8644019b7880c57c50cd908f179a MD5 | raw file
  1. // Todo Model
  2. // ----------
  3. define(function () {
  4. 'use strict';
  5. var module = {};
  6. module.create = function (properties) {
  7. // Our basic **Todo** model has 'text', 'order', and 'done' attributes.
  8. var Todo = Backbone.Model.extend({
  9. // Default attributes for a todo item.
  10. defaults: function () {
  11. return {
  12. done: false,
  13. order: properties.collection.nextOrder()
  14. };
  15. },
  16. // Toggle the 'done' state of this todo item.
  17. toggle: function () {
  18. this.save({done: !this.get("done")});
  19. }
  20. });
  21. return Todo;
  22. };
  23. return module;
  24. });