Procházet zdrojové kódy

Step 3.2: Modify App component to get tasks from collection.

Frederic G. MARAND před 9 roky
rodič
revize
05005748a6
1 změnil soubory, kde provedl 13 přidání a 7 odebrání
  1. 13 7
      App.jsx

+ 13 - 7
App.jsx

@@ -1,16 +1,22 @@
 // App component : represents the whole app.
 
 App = React.createClass({
-  getTasks() {
-    return [
-      { _id: 1, text: "This is task 1" },
-      { _id: 2, text: "This is task 2" },
-      { _id: 3, text: "This is task 3" }
-    ];
+
+  // This mixin makes the getMeteorData work.
+  mixins: [ReactMeteorData],
+
+  // Loads items from the Tasks collection and puts them on this.data.tasks.
+  getMeteorData() {
+    let result = {
+      tasks: Tasks.find({}).fetch()
+    };
+    // Meteor._debug("result", result);
+    return result;
   },
 
   renderTasks() {
-    return this.getTasks().map((task) => {
+    return this.data.tasks.map((task) => {
+      // Meteor._debug(task._id);
       return <Task key={task._id} task={task} />;
     });
   },