1

I've been going over this code for a while now.This is the process:

I'm retrieving some data from a server. These data will displayed on cards using the .map function.

The problem is: They are displaying on the cards but not on the attached modals

Focus on the code blocks with double slash comments "//"

// I started with the map function here 
if(this.state.isLoading === false) {
this.state.data.map((datii,i) => {

  if(isClicked){
    generateButton =    
            <button type="button" className="btn btn-primary" id="postStatus"
                                data-dismiss="modal" data-toggle="modal" data-target={"#exampleModal2"} 
                            onClick={this.handleGeneratedClick} aria-label="Close">
                            Post on social media
                        </button>

    generated = <div className="row">
                  <p className="col-3"><b>Generated Link:</b></p>
                  <p className="col-9">The generated link</p>
                </div>
  }else {        
    generateButton = <button type="button" className="btn btn-primary" onClick={this.handleGeneratedClick}>
                        Generate link
                      </button>
    generated = <div/>
  }

  return(

  content.push(
    <div className="contents" key={datii.campaignId}>



                //datii not showing visible here
                ////modal 1 div

               <div className="modal fade" id={"exampleModal"} tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
               <div className="modal-dialog" role="document">
                 <div className="modal-content">
                   <div className="modal-header">
                     <h5 className="modal-title" id="exampleModalLabel"><b>CAMPAIGN DETAILS</b></h5>
                     <button type="button" className="close" data-dismiss="modal" aria-label="Close">
                       <span aria-hidden="true">&times;</span>
                     </button>
                   </div>
                   <div className="modal-body" >
                       <div className="container-fluid text-left">
                          <div className="row">
                             <p className="col-3"><b>Name:</b></p>
                             <p className="col-9">{datii.campaignName}</p>
                           </div>
                           <div className="row">
                             <p className="col-3"><b>Duration:</b></p>
                             <p className="col-9">{datii.startTime + " - " + datii.endTime }</p>
                           </div>
                           <div className="row">
                             <p className="col-3"><b>Hashtags:</b></p>
                             <p className="col-9">{datii.hashTags}</p>
                           </div>
                           <div className="row">
                             <p className="col-3"><b>Image(s):</b></p>
                             <div className="col-9">
                              <div className="row">


                              <img src="" className="img-fluid mx-auto d-block col-6" alt="campaigns" />
                              <img src="" className="img-fluid mx-auto d-block col-6" alt="campaigns" />
                              </div>
                             </div>
                           </div>


                            {generated}
                       </div>
                   </div>


                      <div className="modal-footer align-self-center">
                        {generateButton}
                     </div>
                 </div>
               </div>
             </div>


                    //and here either
                    //modal 2 div


             <div className="modal fade" id={"exampleModal2"+i} tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel2" aria-hidden="true">
               <div className="modal-dialog" role="document">
                 <div className="modal-content">
                   <div className="modal-header">
                     <h3 className="modal-title" id="exampleModalLabel2"><b>Share on social media</b></h3>
                     <button type="button" className="close" data-dismiss="modal" aria-label="Close">
                       <span aria-hidden="true">&times;</span>
                     </button>
                   </div>
                   <div className="modal-body">
                       <div className="container-fluid">
                          <div className="row">
                             <h5 className="col text-left p-0"><b>{datii.campaignName}</b></h5>
                           </div>
                           <div className="row">
                            <textarea className="form-control" id="exampleFormControlTextarea1" rows="3">
                            </textarea>
                           </div>

                   <div className="mb-4">
                   <div className="row">

                <button type="button" className="btn btn-primary col-5">Post</button>
                    </div>
                   </div>
                 </div>
               </div>
             </div>



            //datii is only visible here
            //card div


            <div className="card text-center">
            <div className="card-body">
              <h5 className="card-title"><b>{datii.campaignName}</b></h5>
                <p className="card-text">{this.state.data[i].samplePost}</p>
              <button className="btn btn-primary viewbtn" data-toggle="modal" data-target={"#exampleModal"+i}>View</button>
            </div>
            </div>
          </div>            
3
  • 3
    Add the relevant code please Commented Jan 17, 2019 at 9:31
  • 2
    show what you tried - stackoverflow.com/help/how-to-ask Commented Jan 17, 2019 at 9:36
  • okay... i'll add it now Commented Jan 17, 2019 at 13:59

1 Answer 1

1

You gotta show us what your code !

But going on a hunch, This is how you can render multiple divs from .map function

    return this.state.serverresponse.map(x=> (
      <div>
          <ExampleComponent
              prop1={x.id}
              prop2={x.data}
              prop3={x.binary}
              prop4={x.label}

          />
        </div>
      ));

this.state.serveresponse is where im storing the result from my server, which in my case is an array of objects.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.