我使用Meteor Files上传文件 . 我设法将它保存到数据库和文件系统,但我无法从其 findOne
方法获取这些文件 . 这是我的产品系列:
import { Mongo } from 'meteor/mongo';
import { Meteor } from 'meteor/meteor';
import Images from './imagesCollection';
const ProductCollection = new Mongo.Collection( 'products' );
ProductCollection.helpers({
photos() {
return Images.findOne({ meta: { productId: this._id } });
}
});
这是我的图像集:
const Images = new FilesCollection({
collectionName: 'Images',
allowClientCode: false,
storagePath: () => {
return `${process.env.PWD}/public/assets/products/`;
},
onBeforeUpload: function(file) {
if (/png|jpe?g/i.test(file.extension)) {
return true;
}
}
});
export default Images;
我用meteor-collection-helper获取与产品相关的图像 .
class ProductBox extends Component {
constructor(props) {
super(props);
this.productRemove = this.productRemove.bind(this);
this.selectUpdate = this.selectUpdate.bind(this);
}
render() {
console.log(this.props.produk.photos())
return (
);
}
}
export default ProductBox;
每当我consol注销图像集合时,它返回undefined或光标无法获取数据 . 请指出我哪个部分做错了?任何帮助都会被贬低!