2017-07-04 7 views
0

何らかの理由で、Locationsコレクションからデータを表示できません。私が{object}オブジェクトを取得するとき、私はHTMLに{{myPlaces}}を書く。コンテンツ全体とすべてのフィールドの一覧が表示されませんか?私はMeteor.UsersとImagesの両方からすべてのデータを取得するので、誰かがこれを説明できますか?ありがとうございました!MeteorがMongoDBからデータを返さない

zipCodes.js: - あなたがLocationsのリストを参照することができますすなわち機能

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

答えて

1

あなたmyPlacesヘルパーはカーソルを返します。 を反復して、{{#each }}を使用して個々の文書を表示する必要があります。あなたのhtmlで:

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

これは私の以前のプロジェクトでやったことであり、覚えられませんでした。どうもありがとうございます!流星を再始動した後に働いた。 – user3323307

関連する問題