Meteor - return asynchronous function to handlebar template?

吃可爱长大的小学妹 提交于 2019-11-30 10:10:41

Use Session as an intermediary. It is reactive so as soon as its set it will change the template with the new data:

Template.backgroundImage.background = function(){
    return Session.get("FlickrObject");
};

Template.backgroundImage.created = function() {
    FlickrRandomPhotoFromSet(setID,function(){
        Session.set("FlickrObject", FlickrObject)
    });
}

So the created method will be run when the template is created to run FlickrRandomPhotoFromSet, when the result is returned it will set the Session hash which in turn will set the background as soon as the result is received.

Be careful with your FlickrRandomPhotoFromSet too, I didn't notice you had an argument for FlickrObject to pass to the callback.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!