Meteor:获取CollectionFS照片博客示例中上传图片的网址(Meteor: Get url of uploaded image in CollectionFS photo-blog example)

我希望能够在教程示例中通过javascript传递上传图像的URL, 在meteor中制作一个photoblog 。

在该示例中(在home.js中),用于呈现图像的模板的帮助器返回Images.find(),其在图像模板(image.html)中用于输出html以通过以下方式显示图像:

<img src="{{url}}" />

这很好,整个教程也是如此,包括S3。 但是,我想将它与另一个项目结合起来,并且需要在程序控制下存储和传递url。

看起来因为模板能够使用{{url}},在js中,在最简单的情况下,可以使用Images.findOne()。url来获取至少第一个url。 例如,我修改了给定的助手来包含这个:

Template.home.helpers({ 'images': function() { console.log("url from home helper: = " + Images.findOne().url); //cannot read url property return Images.find(); } });

但是,这会收到错误“无法读取url属性...”(之后,由于某种原因,控制台会打印出大量的源代码!!)如果模板能够呈现字段“url”收集图像对象,为什么不能看到它?

如何在javascript中获取网址?

I'd like to be able to pass the URL of an uploaded image in javascript in the tutorial example making a photoblog in meteor.

In that example (in home.js), the helper for templates that render images returns Images.find(), which is used in the image template (image.html) to output html to show the image via:

<img src="{{url}}" />

This works fine, as does the entire tutorial, including S3. However, I'd like to combine it with another project, and that one will require storing and passing around the url under program control.

It would seem that because the template is able to use {{url}}, that in js, one could, in the simplest case, use Images.findOne().url to get at least the first url. E.g., I have modified the given helper to contain this:

Template.home.helpers({ 'images': function() { console.log("url from home helper: = " + Images.findOne().url); //cannot read url property return Images.find(); } });

However, this gets the error "cannot read url property..." (and after that, for some reason, the console prints out a huge batch of source code!!) If the template is able to render the field "url" from the collection image object, why can't js see it?

How can I get at the url in javascript?

最满意答案

url是函数而不是属性所以你必须使用Images.findOne().url()而不是Images.findOne().url

要么

如果你得到相同的错误,因为你的findone方法返回undefined。 有可能的问题。

您的图像集合为空。 您没有发布图像而不订阅图像。 您可能在上传图像之前使用此调用。

我希望这可以解决你的问题。

the url is the function not the property so you have to use Images.findOne().url() not the Images.findOne().url

or

if you are getting the same error that because your findone method return undefined. There are the possible issues.

Your Images collection are empty. You did not publish then images and not subscribe the images. You may be using this call before uploading the images.

I hope this this may solve your issue.

Meteor:获取CollectionFS照片博客示例中上传图片的网址(Meteor: Get url of uploaded image in CollectionFS photo-blog example)

我希望能够在教程示例中通过javascript传递上传图像的URL, 在meteor中制作一个photoblog 。

在该示例中(在home.js中),用于呈现图像的模板的帮助器返回Images.find(),其在图像模板(image.html)中用于输出html以通过以下方式显示图像:

<img src="{{url}}" />

这很好,整个教程也是如此,包括S3。 但是,我想将它与另一个项目结合起来,并且需要在程序控制下存储和传递url。

看起来因为模板能够使用{{url}},在js中,在最简单的情况下,可以使用Images.findOne()。url来获取至少第一个url。 例如,我修改了给定的助手来包含这个:

Template.home.helpers({ 'images': function() { console.log("url from home helper: = " + Images.findOne().url); //cannot read url property return Images.find(); } });

但是,这会收到错误“无法读取url属性...”(之后,由于某种原因,控制台会打印出大量的源代码!!)如果模板能够呈现字段“url”收集图像对象,为什么不能看到它?

如何在javascript中获取网址?

I'd like to be able to pass the URL of an uploaded image in javascript in the tutorial example making a photoblog in meteor.

In that example (in home.js), the helper for templates that render images returns Images.find(), which is used in the image template (image.html) to output html to show the image via:

<img src="{{url}}" />

This works fine, as does the entire tutorial, including S3. However, I'd like to combine it with another project, and that one will require storing and passing around the url under program control.

It would seem that because the template is able to use {{url}}, that in js, one could, in the simplest case, use Images.findOne().url to get at least the first url. E.g., I have modified the given helper to contain this:

Template.home.helpers({ 'images': function() { console.log("url from home helper: = " + Images.findOne().url); //cannot read url property return Images.find(); } });

However, this gets the error "cannot read url property..." (and after that, for some reason, the console prints out a huge batch of source code!!) If the template is able to render the field "url" from the collection image object, why can't js see it?

How can I get at the url in javascript?

最满意答案

url是函数而不是属性所以你必须使用Images.findOne().url()而不是Images.findOne().url

要么

如果你得到相同的错误,因为你的findone方法返回undefined。 有可能的问题。

您的图像集合为空。 您没有发布图像而不订阅图像。 您可能在上传图像之前使用此调用。

我希望这可以解决你的问题。

the url is the function not the property so you have to use Images.findOne().url() not the Images.findOne().url

or

if you are getting the same error that because your findone method return undefined. There are the possible issues.

Your Images collection are empty. You did not publish then images and not subscribe the images. You may be using this call before uploading the images.

I hope this this may solve your issue.