0

I'm trying to display checkbox of some of the popular links but I face this problem. I can't return more than one item (first one). Any Ideas how to display all of them (5).

private getItems(){
        let items:JSX.Element;
        let data=this.state.items;
        for(let i=0;i<data.length;i++){
          if(data[i].Title="Google"){
             items= (
              <div>
            <Checkbox
              label={data[i].Title}
              disabled={ true }
              defaultChecked={ true }
              styles={ styles }
            />
            <br/>
          </div>);
        }
        else if(data[i].Title="Yahoo"){
           items= (
           <div>
             <Checkbox
               label={data[i].Title}
               disabled={ false }
               defaultChecked={ true }
               styles={ styles }
             />
             <br/>
           </div>);
         }
         else{
           items= (
          <div>
            <Checkbox
              label={data[i].Title}
              disabled={ false }
              defaultChecked={ false }
              styles={ styles }
            />
            <br/>
          </div>);
         }
          console.log(data[i].Title);

         return items;
      } 
  }
2
  • Can you explain a bit over your expected result because its not clear.
    – Sunil Sahu
    May 29, 2018 at 4:36
  • Sure, I'm expecting 5 check boxes with names of the popular search engines. First one should be Google and the user should be not allowed to change. Next checkbox should be Yahoo and it should be checked. Next 3 checkboxes should be unchecked. Receiving data from SP list - let data=this.state.items; hope this explain everything. 😊 May 29, 2018 at 5:21

1 Answer 1

1

I used this to write answer:

let googleitem:JSX.Element;
let yahooitem:JSX.Element;
let item:JSX.Element;
let items = [];
let data=this.state.items;
for(let i=0;i<data.length;i++){
   if(data[i].Title="Google"){
      googleitem = (your code);
   }
   else if(data[i].Title="Yahoo"){
      yahooitem = (your code);
   }
   else{
      item = (your code);
      items = [...items,item];
   }
}
items = [googleitem,yahooitem,...items];

May be error since I didn't use it before. But the trouble is that you must use array to store your checkboxes.

1
  • Obviously, I forgot about this detail hahaha Thanks @AlexZh! May 29, 2018 at 9:36

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.