gpt4 book ai didi

javascript - Meteor 不从 MongoDB 返回数据

转载 作者:行者123 更新时间:2023-12-03 03:56:39 25 4
gpt4 key购买 nike

由于某种原因,我无法从我的位置集合中获取显示的数据。无论我输入什么,当我在 HTML 中写入 {{myPlaces}} 时,我都会得到 [object Object]。我不应该获得全部内容和列出的所有字段的列表吗?有人可以解释一下吗,因为我从 Meteor.Users 和 Images 获取所有数据。谢谢!

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

最佳答案

您的 myPlaces 帮助程序返回一个光标 - 即一个可让您引用位置列表的函数。您需要使用{{#each }}迭代该光标来显示各个文档。在你的 html 中执行以下操作:

<template name="locations">
{{#each myPlaces}}
place: {{place}}
country: {{country}}
zipcode: {{zipcode}}
{{/each}}
</template>

关于javascript - Meteor 不从 MongoDB 返回数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44912745/

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