Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9254723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:32:35+00:00 2026-06-18T11:32:35+00:00

I’ learning meteor to write a simple app to pull information from one collection

  • 0

I’ learning meteor to write a simple app to pull information from one collection (a set of , and based on what is returned from that collection (a big list of items, names and item IDs), do a lookup in a different collection for an item name. My thinking was that the the item collection only be published on the server because it’s big and the clients don’t need direct access to it.

Everything more or less works, except I don’t think I’ve handled the callback correctly. Here is the simple test I wrote. The template where I pass the name of the item:

Template.operations.getTypeID = function(name) {
  result = "";
  console.log("Precall Logging name: ", name);
  console.log("Precall Logging result: ", result);

  result = Meteor.call('getID', name, function (error, result) {
    console.log("Async Logging in call: result: ", result);
  });

  console.log("Name is now", name);
  console.log("Result is now", result);

  return name;
}

Here is the Method on the server where I’ll eventually look up the ID based on the name:

Meteor.methods({ 

        getID: function(itemName) {
            result = itemName + "_changed";
            console.log("server: getID result:", result);

            return result;
         }

});

And here is where I call the template in the HTML file:

<td>{{getTypeID name}}</td>

When I’m using the app I can see that the Method getID is called in what looks like an asynch manner – the result in the getID method changes and is written to the console after the other entries in the template. How do I get set the result that is returned in the callback to be usable in the template and returned to the client so that I can render that in the page?

Update: Here is my console.log output after making some edits:

Precall Logging name:  Apples lootlog.js:79
Precall Logging result:   lootlog.js:80
Name is now Apples lootlog.js:86
Result is now undefined lootlog.js:87
Precall Logging name:  Oranges lootlog.js:79
Precall Logging result:   lootlog.js:80
Name is now Oranges lootlog.js:86
Result is now undefined lootlog.js:87
Precall Logging name:  Melons lootlog.js:79
Precall Logging result:   lootlog.js:80
Name is now Melons lootlog.js:86
Result is now undefined lootlog.js:87
Precall Logging name:  Grapes lootlog.js:79
Precall Logging result:   lootlog.js:80
Name is now Grapes lootlog.js:86
Result is now undefined lootlog.js:87
Precall Logging name:  Onion lootlog.js:79
Precall Logging result:   lootlog.js:80
Name is now Onion lootlog.js:86
Result is now undefined lootlog.js:87
Async Logging in call: result:  Apples_changed lootlog.js:83
Async Logging in call: result:  Oranges_changed lootlog.js:83
Async Logging in call: result:  Melons_changed lootlog.js:83
Async Logging in call: result:  Grapes_changed lootlog.js:83
Async Logging in call: result:  Onion_changed 

Here is what is printed to the meteor console:

server: getID Name: Apples
server: getID result: Apples_changed
server: getID Name: Oranges
server: getID result: Oranges_changed
server: getID Name: Melons
server: getID result: Melons_changed
server: getID Name: Grapes
server: getID result: Grapes_changed
server: getID Name: Onion
server: getID result: Onion_changed
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T11:32:36+00:00Added an answer on June 18, 2026 at 11:32 am

    I wouldn’t recommend the paradigm being used to transport data to the template, for each item being looped you’re making a Meteor.call to the server, which in a higher latency environment really slows things down.

    The template helper has a Meteor.call inside which can’t run synchronously on the client side, so you have to pass the results to a reactive variable such as Session, which in turn passes them to the template.

    I would recommend you make one call instead of many small ones, in the code below I’ve used one call with an array of names.

    Server

    Meteor.methods({ 
            //Input variable is an array of names
            getID: function(itemNameArray) {
                result = {};  //Initialize an empty array
    
                itemNameArray.forEach(function(entry) {
                    itemNameArray[entry] = entry + "_changed";
                });
                return result;
             }
    });
    

    Client

    Template.operations.getTypeID = function(name) {
        Session.get("variables")[name];
    }
    
    Meteor.call('getID', ["Apples", "Oranges", "Grapes", "Onions"], function (error, result) {
        Session.set("variables", result);
    });
    

    Again I’m not sure exactly what you want to do but you could replace the array with the data source of wherever you got the names from.

    Session.set/get is reactive so as soon as Meteor gets the data from the server it will update the templates accordingly

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small JavaScript validation script that validates inputs based on Regex. I
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a view passing on information from a database: def serve_article(request, id): served_article
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.