【发布时间】:2021-04-16 11:53:53
【问题描述】:
所以我有一个简单的服务器文件:
import { Meteor } from 'meteor/meteor';
const Animals = new Mongo.Collection("animals");
let animalsFindOne = Targets.findOne({animal: "henry"});
console.log(_.get(animalsFindOne, 'food.favorite.amount'));
还有一个呈现给模板的animals.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”,这是预期的输出并且很棒。
我在这里遗漏了什么?
编辑:我还安装了自动发布功能,我不期待删除它,因为这个软件无论如何都是一个测试。
【问题讨论】:
标签: meteor meteor-blaze meteor-collections