12345678910111213141516171819202122232425262728293031323334353637 |
- const TodoList = Backbone.Collection.extend({
- model: TodoItem,
- url: '/server/todos',
- });
- $(function () {
- // Make a global instance
- todoList = new TodoList();
- // Get number of items
- console.log('List length', todoList.length);
- // Push item
- todoList.add(todoItem);
- console.log('List length after add', todoList.length);
- // Get item at index
- const id = todoList.at(0).get('id');
- // Get item by id.
- const item = todoList.get(id);
- console.log(`Item with id ${id} is the added item ?`, item === todoItem);
- todoList.remove(item);
- console.log('List length after remove', todoList.length);
- // todoList.reset([
- // { description: "Pick up milk", status: "incomplete" },
- // { description: "Do the dishes", status: "incomplete" },
- // { description: "Learn backbone", status: "incomplete" },
- // ]);
- //
- // console.log('List after reset', todoList.toJSON());
- todoList.fetch({ async: false });
- console.log('List after fetch', todoList.toJSON());
- });
|