gpt4 book ai didi

javascript - 无法使用 Meteor-Blaze 访问 Mongo 数据库

转载 作者:行者123 更新时间:2023-11-28 05:22:52 25 4
gpt4 key购买 nike

在“reports.html”同一文件夹中的“reports.js”文件中使用此代码,我在返回的数组中得到 0 个元素。不确定我是否缺少任何额外的声明,但我也不能使用“import { Mongo } from 'meteor/mongo';”没有错误“使用保留字‘导入’”。 meteor 版本1.2.1

JS

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({});
},
});

HTML

<Template name="dashboardd">
{{#each options}}
<p><label>{{text}}</label></p>
{{/each}}
</Template>

最佳答案

据我所知,meteor 1.2 不支持导入。导入是在 Meteor 1.3 或 1.4 中添加的新模块,我不确定。在处理集合时我总是使用这 3 个元素(如果我们采用集合声明则为 4 个元素)

您应该在服务器端进行一些发布并允许:

Meteor.publish("Tasks ", function (selector, options) {
//you can remove condition if you dont have accounts-package
if (this.userId) {
return Tasks .find(selector || {}, options || {});
}
});

还有一些允许 再说一次,如果你没有 Meteor 帐户,你可以简单地 - 在插入、更新等时返回 true。但我不能说这不安全:P

Tasks.allow({
insert: function (userId, doc) {
return userId;
},

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

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

在客户端进行一些订阅

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
});
});

关于javascript - 无法使用 Meteor-Blaze 访问 Mongo 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40408894/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com