我正在尝试用我自己的一个替换默认的Yelp星级评级图像.为此,我需要为可能已加载的每个可能的5个图像找到相应的图像源.然后,基于我需要加载我创建的正确图像.
<div id="starRating">
<img src="http://yelp-star-1.png"/>
</div>
Run Code Online (Sandbox Code Playgroud)
所以,yelp-star-1.png将被my-star-1.png取代.等等等等.这可能很简单,但我是jQuery的新手,我发现的一切都没有正常工作.非常感谢您的专业知识!
我正在使用fetch从本地 API 返回一些数据。我能够返回数据并设置状态。但是,在我的render()函数中,当使用map和尝试访问比数据中的顶级对象更深的任何内容时,我会收到undefined错误消息。我可以正确地将我想要的任何级别的数据记录到控制台,但我无法在呈现的组件中访问它。
constructor(props) {
super(props);
this.state ={
verifications: []
}
}
componentWillMount(){
fetch('http://localhost:3001/verifications')
.then(response => response.json())
.then((verifications) => {
this.setState({verifications})
console.log(this.state);
});
}
Run Code Online (Sandbox Code Playgroud)
在我的渲染中
{this.state.verifications.map(verification =>
<div key={verification._id}>
<ReviewListItem
hasAvatar={true}
imageUrl={verification.supplier.logo}
title={verification.supplier.companyName}
description={verification.tasks.length}
/>
</div>
)}
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
Unhandled Rejection (TypeError): Cannot read property 'logo' of null
我已经四处寻找答案,但我觉得我一定是在接近这个错误。我来自 Angular 1,我对 React 非常陌生。也许我很难理解这些概念。
这是我的数据:
[
{
"_id": 1000,
"supplier": {
"_id": 1000,
"companyName": "ACME Business Ventures",
"logo": "/images/logos/suppliers/acme.jpg",
"avettaId": "ADS83J",
"brandColor": "#563E5E",
"clients": …Run Code Online (Sandbox Code Playgroud)