search

Home  >  Q&A  >  body text

How to check print friendly value using If else condition in render function

How to check conditions in render function to print friendly names For example if (value = 101) then “some text”, else if (value = 102) then “Another text” etc. Please check below the code I am trying.

public render(): React.ReactElement<IGetSpListsProps> {
return (
<div>
<ol>
{
this.state.sitecontents.map(function(mylists,mylistitemkey){
return(
<li>
  <span>{mylists.Title}</span> //here it will display list titles
  
  if({mylists.BaseTemplate} = {'101'} // basetemplate will return int number like 100, 101, 103 etc so checking the condition with 101
  {
    <p>{"Generic List template"}</p>
  }
  else if ({mylists.BaseTemplate} = {'102'}) {
    <p>{"Document List template"}</p>
  } else {
    <p>{"Custom template"}</p>
  })
  
  </li>);
  })
}</ol></div>
  );

{mylists.BaseTemplate} will return the template number so I want to print the friendly name of that template number, I am trying to print but it is not expected. Please check how the output is displayed If we see the screenshot below, the condition is treated as simple text

How to use if else to check conditions Or is there any way to create a file/Json value and lookup from that file to get the corresponding friendly string?

P粉744831602P粉744831602437 days ago429

reply all(1)I'll reply

  • P粉121081658

    P粉1210816582023-09-15 09:25:47

    Have you tried Status? You can get this idea here

    reply
    0
  • Cancelreply