我正在嘗試構建一個非常簡單的流星應用。我已經實施了所有CRUD。但我的問題是當我使用發佈,然後訂閱,沒有數據返回。我下面的代碼給出:流星:訂閱不工作
進口\ API \任務\ tasks.js
import { Mongo } from 'meteor/mongo';
import { Meteor } from 'meteor/meteor';
TasksSchema = new SimpleSchema({
title: {
type: String
},
owner: {
type: String
}
});
export const Tasks = new Mongo.Collection('tasks', { schema: TasksSchema });
if (Meteor.isServer) {
Meteor.publish('task.list', function() {
return Tasks.find({ owner: this.userId });
});
}
進口\ UI \分量\家\ home.js
import { Tasks } from '/imports/api/tasks/tasks.js';
import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating'
import { ReactiveDict } from 'meteor/reactive-dict';
import './home.html';
if (Meteor.isClient) {
Template.home.onCreated(function bodyOnCreated() {
Meteor.subscribe('task.list');
});
Template.home.helpers({
tasks() {
let userId = Meteor.userId();
return Tasks.find({ owner: userId }, { sort: { updatedAt: -1 } });
}
});
}
進口\ ui \ components \ home \ home.html
<!-- here nothing is shown,although I have data -->
{{#each task in tasks }}
{{task.title}}
{{/each}}
有什麼建議嗎?提前致謝。
取而代之的更多信息'{{task.title}}''嘗試的{{title}}',也爲您在瀏覽器控制檯'Task.find({}) .fetch()'看看你是否可以看到記錄 – Sasikanth
它工作@Sasikanth,謝謝 – sabbir
我發佈它作爲答案,你可以接受它來關閉問題。 – Sasikanth