【发布时间】:2023-04-03 18:03:01
【问题描述】:
我有一个订阅项目的组件。 这些项目被确认在那里,就好像我使用以下它返回带有项目的光标:
console.log(Items.find({key: itemKey}).fetch());
项目集合被导入等
我的构造函数:
constructor(){
super();
this.state = {
subscription: {
items: Meteor.subscribe("allItems")
}
}
}
我的组件将卸载方法:
componentWillUnmount(){
this.state.subscription.items.stop();
}
这是问题所在的方法。错误是 Uncaught TypeError: Cannot read property 'srcEntire' of undefined:
getItemSource(itemKey){
console.log(itemKey); // shows the correct key
var itemer = Items.findOne({key: itemKey});
console.log(itemer.srcEntire);
return itemer.srcEntire;
}
渲染部分(如果我硬编码getItemSource方法的返回值,它会显示图像。通过调用getItemSource方法并传入传入的图层道具(道具工作)找到图像的来源:
render(){
return (
<div className="col-lg-3" >
<img id="myLayer" className="on-top img-responsive center-block on-top " name="myLayer" src={this.getItemSource(this.props.layers.myLayer)} />
</div>
)}
【问题讨论】:
标签: javascript mongodb meteor reactjs