소스 검색

Commit 11.2: Add publish and subscribe.

Frederic G. MARAND 8 년 전
부모
커밋
4df3e171de
1개의 변경된 파일9개의 추가작업 그리고 0개의 파일을 삭제
  1. 9 0
      simple-todos.js

+ 9 - 0
simple-todos.js

@@ -1,7 +1,16 @@
 Tasks = new Mongo.Collection("tasks");
 
+if (Meteor.isServer) {
+  Meteor.publish('tasks', function () {
+    var ret = Tasks.find();
+    return ret;
+  })
+}
+
 if (Meteor.isClient) {
   // This code only runs on the client
+  Meteor.subscribe('tasks');
+
   Template.body.helpers({
     tasks: function () {
       if (Session.get('hideCompleted')) {