Retrieving Data from Meteor Collections

前端 未结 5 1332
北恋
北恋 2021-02-08 18:54

I\'m having a few problems when trying to get data from a Meteor Collection and I need some advice.

The collection has been defined, published, and subscribed successful

5条回答
  •  臣服心动
    2021-02-08 19:26

    You are working on the client and you never know when the client got all the data you need. Your functions can be fired when the collections are empty or still not finished synchronized. So you have to make a deferred request to your minimongo (when all data is available local)

    And yes you can´t access stuff when its not rendered in the DOM via getElementById() or something but in your case you try to access data from the minimongo (your local mongodb version in the browser) not the DOM so your template is not important here.

    Just wait until your subscribtion is ready that your minimongo own all the data with the onReady callback in your subscribtion call and fire your functions.

    https://docs.meteor.com/api/pubsub.html#Meteor-subscribe

    callbacks (Function or Object).

    Optional. May include onStop and onReady callbacks. If there is an error, it is passed as an argument to onStop. If a function is passed instead of an object, it is interpreted as an onReady callback.

提交回复
热议问题