由于某种原因,我无法从我的Locations集合中显示数据。无论我输入什么,当我在HTML中编写{{myPlaces}}时,我会得到[object Object]。我不应该列出整个内容和列出的所有字段吗?有人可以解释这一点,因为我从Meteor.Users和图像中获取所有数据。谢谢!
zipCodes.js:
import { Mongo } from 'meteor/mongo';
export const Locations = new Mongo.Collection('locations');
if (Meteor.isServer) {
Meteor.publish("locations", function () {
return Locations.find().cursor;
});
}
if (Meteor.isServer) {
Locations.batchInsert(
[
{
"country": "NO",
"zipcode": 1751,
"place": "Halden",
"county": "Ostfold",
"countyNumber": 1,
"municipality": "Halden",
"municipalityNumber": 101,
"lat": 59.1248,
"long": 11.3875,
"num": 4
},
{
"country": "NO",
"zipcode": 1752,
"place": "Halden",
"county": "Ostfold",
"countyNumber": 1,
"municipality": "Halden",
"municipalityNumber": 101,
"lat": 59.1248,
"long": 11.3875,
"num": 4
},
testPage.js
import './testPage.html';
import { Template } from 'meteor/templating';
import Images from '/lib/config/imagesCollection.js';
import { Locations } from '/imports/api/profiles/zipCodes.js';
Template.testPage.helpers({
// PROFILE INFORMATION
user: function() {
return Meteor.users.find();
},
// this = {{#each user}} context
userEmail: function() {
return this.emails[0].address;
},
userFirstName: function() {
return this.profile.first_name;
},
userTitle: function() {
return this.profile.work_title;
},
userMobile: function() {
return this.profile.mobile;
},
userZip: function() {
return this.profile.zipcode;
},
// PATH TO PROFILE PICTURE
imageLink: function() {
return Images.findOne({userId: this._id})['_id'];
},
// GEODATA TEST
myPlaces: function() {
return Locations.find({});
},
});
答案 0 :(得分:1)
您的myPlaces
助手会返回光标 - 即可让您引用Locations
列表的功能。您需要迭代覆盖该光标以使用{{#each }}
显示单个文档。在你的html中:
<template name="locations">
{{#each myPlaces}}
place: {{place}}
country: {{country}}
zipcode: {{zipcode}}
{{/each}}
</template>