Browse Source

Level 1.3: transforming attributes during parse.

Frederic G. MARAND 6 years ago
parent
commit
be5d8d3250
3 changed files with 9 additions and 2 deletions
  1. 4 0
      src/Controllers/TodosController.php
  2. 4 1
      web/client/src/todoModel.js
  3. 1 1
      web/data/items.json

+ 4 - 0
src/Controllers/TodosController.php

@@ -31,6 +31,10 @@ class TodosController {
     $todo = $todos[$id]
       ? ['todo' => $todos[$id]]
       : NULL;
+    if ($todo) {
+      $todo['todo']['desc'] = $todo['todo']['description'];
+      unset($todo['todo']['description']);
+    }
     return $app->json($todo);
   }
 

+ 4 - 1
web/client/src/todoModel.js

@@ -12,7 +12,10 @@ const TodoItem = Backbone.Model.extend({
 
     // Long format for arrow function to allow breakpoint setting in Chrome.
     parse: (response) => {
-      return response.todo;
+      const todo = response.todo;
+      todo.desc = todo.description;
+      delete todo.description;
+      return todo;
     },
 
     toggleStatus(view) {

+ 1 - 1
web/data/items.json

@@ -1,7 +1,7 @@
 {
     "1": {
         "id": 1,
-        "description": "some description",
+        "description": "some other description",
         "status": "incomplete"
     },
     "2": {