0

I am writing a image slider for my project.In there, the image will not get when I post a dynamic id with Link tag.I save the image path in 'assests/images/'.Why not show the image?Please, advice me.My code is here. This is link component.

<div>
    <switch>
        <Header />
        <TourPackageDetail data={this.props.match.params.id} />
        <Footer />
    </switch>    
</div>

This is the getting json api and setting the image path.

componentWillMount() {
    var id=this.props.data;
    return fetch('http://192.168.1.119:8080/api/viewOneTourPackage/'+id)
        .then(response =>
            response.json()
        )
        .then(responseJson => {
            this.setState({
                package: responseJson,
                picture: responseJson.picture
            });
            console.log(this.state.package);
        })
        .catch((error) => {
            console.log(error)
        });
    }
render() {
    return (
        <div class="carousel-inner" role="listbox">
            {
                this.state.picture.map((getIndex, i) =>
                    i === 0 ?
                    (
                        <div class="item active">
                            <img src={this.props.getIndex} alt={i} style={{ width: "100%", height: "auto" }} />
                        </div>
                    ):
                    (
                        <div class="item">
                            <img src={this.props.getIndex} alt={i} style={{ width: "100%", height: "auto" }} />
                        </div>
                    )
                )
            }
        </div>
    )
}
Surya Purohit
  • 1,090
  • 1
  • 9
  • 29
kmk
  • 11
  • 5

1 Answers1

1

I guess this part of the code has the problem. You are accessing the iterated map Value through props. Can you try with this

`

{
this.state.picture.map((pictureSrc, i) =>
i === 0 ?
(
<div class="item active">
<img src={pictureSrc} alt={i} style={{ width: "100%", height: "auto" }} />
/div>
) :
(
<div class="item">
<img src={pictureSrc} alt={i} style={{ width: "100%", height: "auto" }} />
</div>
)
)
}

`

Jayabalaji J
  • 1,016
  • 7
  • 9