首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使用Meteor-Blaze访问Mongo

无法使用Meteor-Blaze访问Mongo
EN

Stack Overflow用户
提问于 2016-11-03 18:33:47
回答 1查看 57关注 0票数 1

使用"reports.js“文件中的代码,在"reports.html”的同一文件夹中,返回数组中的0元素。不确定我是否遗漏了任何额外的声明,但我也不能使用“从‘meteor/ Mongo’中导入{mongo};”而没有错误“使用保留的单词'import'”。流星版本1.2.1

JS

代码语言:javascript
复制
Tasks = new Mongo.Collection('tasks');

if(Meteor.isClient){
    Template.reports.rendered = function(){
        if(Session.get("animateChild")){

            $(".reports-page").addClass("ng-enter");

            setTimeout(function(){
                $(".reports-page").addClass("ng-enter-active");
            }, 300);

            setTimeout(function(){
                $(".reports-page").removeClass("ng-enter");
                $(".reports-page").removeClass("ng-enter-active");
            }, 600);
        }
    };
}

Template.dashboardd.helpers({
  options() {
    return Tasks.find({});
  },
});

代码语言:javascript
复制
<Template name="dashboardd">
  {{#each options}}
    <p><label>{{text}}</label></p>
  {{/each}}
</Template>
EN

回答 1

Stack Overflow用户

发布于 2016-11-03 21:30:53

AFAIK流星1.2不支持进口。Improrts是新的模块,增加了I流星1.3或1.4我不确定。在处理集合时,我总是使用这3个元素(如果我们使用集合声明,则使用4个元素)。

您应该在服务器端执行一些发布,并允许如下所示:

代码语言:javascript
复制
Meteor.publish("Tasks ", function (selector, options) {
//you can remove condition if you dont have accounts-package
   if (this.userId) {
    return Tasks .find(selector || {}, options || {});
   }
});

如果你没有流星账户,你可以简单地返回true,插入,更新等。但是我不想说这是不安全的。

代码语言:javascript
复制
Tasks.allow({
 insert: function (userId, doc) {
return userId;
},

 update: function (userId, doc) {
    return userId;
 },

 remove: function (userId) {
  return userId;
 },
});

在客户端有一些订阅

代码语言:javascript
复制
Template.YourTemplateName.onCreated(function () {
 this.autorun(() => {

    this.subscribe('Tasks', { _id: Template.currentData()._id });
 //or
   this.subscribe('Tasks');
 //but this solution can kill Browser when you collection will have a thousand elements. Allways try to not subscribe all collection. Only Needed fields/objects
  });
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40408894

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档