Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Rest API属性条件呈现和ReactJs中字符串的替换_Reactjs_Jsx - Fatal编程技术网

Rest API属性条件呈现和ReactJs中字符串的替换

Rest API属性条件呈现和ReactJs中字符串的替换,reactjs,jsx,Reactjs,Jsx,我正在尝试从react中的restapi获取数据,并且正在使用Axios成功地获取数据。我从restapi获得的属性是uniqueName、Title和documentType。最后一个属性“documentType”值为“发票”或“请购单” 仅对于最后一个属性,要求是,如果documentType的值是“invoice”,那么打印一条消息“It's invoice”,或者如果该值是requisition,则打印消息“It's requisition.我是新手,不知道如何在render方法中应用

我正在尝试从react中的restapi获取数据,并且正在使用Axios成功地获取数据。我从restapi获得的属性是uniqueName、Title和documentType。最后一个属性“documentType”值为“发票”或“请购单”

仅对于最后一个属性,要求是,如果documentType的值是“invoice”,那么打印一条消息“It's invoice”,或者如果该值是requisition,则打印消息“It's requisition.我是新手,不知道如何在render方法中应用if条件。 这是我的密码

返回(
{this.state.errorMessage&&(
{this.state.errorMessage}
)}
    {records.map((记录,索引)=>(
  • 请购单:{record.uniqueName}-标题:{record.Title} 如果({record.documentType=='requisition'}){ 这是请购单 } 其他的 { 这是发票 }
  • ))}
)

谢谢大家:-)

{
}
s中使用条件运算符:

return (
    <div>
        {this.state.errorMessage && (
            <h3 className="error">{this.state.errorMessage}</h3>
        )}
        <ul>
            {records.map((record, index) => (
                <li key={index}>
                    Requisition : {record.uniqueName} - Title : {record.Title}
                    {
                        record.documentType == 'requisition'
                            ? <h1>It's Requisition</h1>
                            : <h1>It's Invoice</h1>
                    }
                </li>
            ))}
        </ul>
    </div>
)
返回(
{this.state.errorMessage&&(
{this.state.errorMessage}
)}
    {records.map((记录,索引)=>(
  • 请购单:{record.uniqueName}-标题:{record.Title} { record.documentType==“请购单” 这是请购单 :这是发票 }
  • ))}
)
我没有话要感谢你。它正在工作。谢谢你,伙计。
return (
    <div>
        {this.state.errorMessage && (
            <h3 className="error">{this.state.errorMessage}</h3>
        )}
        <ul>
            {records.map((record, index) => (
                <li key={index}>
                    Requisition : {record.uniqueName} - Title : {record.Title}
                    {
                        record.documentType == 'requisition'
                            ? <h1>It's Requisition</h1>
                            : <h1>It's Invoice</h1>
                    }
                </li>
            ))}
        </ul>
    </div>
)