Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Meteor查询在服务器上运行良好,但在客户端上运行不好_Meteor_Meteor Blaze_Meteor Collections - Fatal编程技术网

Meteor查询在服务器上运行良好,但在客户端上运行不好

Meteor查询在服务器上运行良好,但在客户端上运行不好,meteor,meteor-blaze,meteor-collections,Meteor,Meteor Blaze,Meteor Collections,因此,我有一个简单的服务器文件: import { Meteor } from 'meteor/meteor'; const Animals = new Mongo.Collection("animals"); let animalsFindOne = Targets.findOne({animal: "henry"}); console.log(_.get(animalsFindOne, 'food.favorite.amount')); 以及呈现

因此,我有一个简单的服务器文件:

import { Meteor } from 'meteor/meteor';

const Animals = new Mongo.Collection("animals");

let animalsFindOne = Targets.findOne({animal: "henry"});
console.log(_.get(animalsFindOne, 'food.favorite.amount'));
以及呈现到模板的
anives.js
文件

import {Template} from "meteor/templating";
import {Mongo} from "meteor/mongo";

import "/imports/ui/targets/animals.html";

const Animals = new Mongo.Collection("animals");
let animalsFindOne = Targets.findOne({animal: "henry"});

Template.targets.helpers({
    foodAmount: function() {
        return _.get(animalsFindOne, 'food.favorite.amount';
    }
});
我可以将“foo”作为foodAmount返回,模板会将其呈现得非常好。对于
.get
我使用
erasaur:meteor-lodash
,它在
server.js
中工作得非常好。在服务器控制台中,输出为“5”,这是预期的、非常好的输出。
我在这里缺了什么?

编辑:我已经安装了autopublish,我不希望删除它,因为这个软件是一个测试。

foodAmount
帮助程序之外已经定义了
animalfindone
,因此它不会触发模板基于反应的重画机制

为了在助手中获得反应能力,您需要在助手中调用查询:

import{Template}来自“meteor/templating”;
从“meteor/Mongo”导入{Mongo};
导入“/imports/ui/targets/animals.html”;
const Animals=新蒙戈收藏(“动物”);
Template.targets.helpers({
foodAmount:function(){
让animalsFindOne=Targets.findOne({animal:henry});
return u.get(animalsFindOne,'food.favorite.amount';
}
});
编辑:Meteor允许使用最新版本,所以此处不需要lodash:

Template.targets.helpers({
foodAmount:function(){
让animalsFindOne=Targets.findOne({animal:henry});
返回动物完成?食物?最爱?数量
}
});

嗯,我想我需要阅读更多关于流星反应性的资料。但非常感谢!流星可选链接的建议也不错。我找不到该功能,然后改为使用lodash:D谢谢!