Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.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
Javascript 从数组中呈现表行:react_Javascript_Reactjs_React Native_Jsx - Fatal编程技术网

Javascript 从数组中呈现表行:react

Javascript 从数组中呈现表行:react,javascript,reactjs,react-native,jsx,Javascript,Reactjs,React Native,Jsx,我试图调用一个函数,在作为道具接收的文本数组上使用map函数渲染表行,但由于某些原因,它们没有被渲染。我是否犯了语法错误?我已经验证了许可证文本道具数组不是空的,只是返回一个字符串数组 const showLicenseText = () => { return licenseText.map(text => { <tr> <ThPadding> License Information {'

我试图调用一个函数,在作为道具接收的文本数组上使用map函数渲染表行,但由于某些原因,它们没有被渲染。我是否犯了语法错误?我已经验证了许可证文本道具数组不是空的,只是返回一个字符串数组

const showLicenseText = () => {
 return licenseText.map(text => {
      <tr>
        <ThPadding>
          License Information
          {':'}
        </ThPadding>
        <td>{text}</td>
      </tr>
  })
}
const showLicenseText=()=>{
返回licenseText.map(text=>{
许可证信息
{':'}
{text}
})
}
render方法中的原始代码是:

return (
  <table>
    <tbody>
      {bbbFileOpenDate && (
        <tr>
          <ThPadding>
            {text.bbbFileOpened}
            {':'}
          </ThPadding>
          <td>{bbbFileOpenDate}</td>
        </tr>
      )}
      {yearsInBusiness && !isOutOfBusiness && (
        <tr>
          <ThPadding>
            {yearsInBusinessLabel}
            {':'}
          </ThPadding>
          <td>{yearsInBusiness}</td>
        </tr>
      )}
      {businessStartDate && (
        <tr>
          <ThPadding>
            {businessStartDateLabel}
            {':'}
          </ThPadding>
          <td>{businessStartDate}</td>
        </tr>
      )}
      {showLicenseText}
      {locationStartDate && (
        <tr>
          <ThPadding>
            {locationStartDateLabel}
            {':'}
          </ThPadding>
          <td>{locationStartDate}</td>
        </tr>
      )} ....
返回(
{bbbFileOpenDate&&(
{text.bbbFileOpened}
{':'}
{bbbFileOpenDate}
)}
{营业年数&!Isofbusiness&&(
{yearsInBusinessLabel}
{':'}
{yearsInBusiness}
)}
{businessStartDate&&(
{businessStartDateLabel}
{':'}
{businessStartDate}
)}
{showLicenseText}
{locationStartDate&&(
{locationStartDateLabel}
{':'}
{locationStartDate}
)} ....

您忘记调用它了!在映射中,因为您使用的是
{}
您需要显式的
返回
语句

  {showLicenseText()}
另外,我将修改如下:

在渲染之外定义函数

showLicenseText = (licenseTextRef) => {
 return licenseTextRef.map(text => {
      return <tr>
        <ThPadding>
          License Information
          {':'}
        </ThPadding>
        <td>{text}</td>
      </tr>
  })
}

==============================

  {this.showLicenseText(licenseText)}
showLicenseText=(licenseTextRef)=>{
返回licenseTextRef.map(文本=>{
返回
许可证信息
{':'}
{text}
})
}
==============================
{this.showLicenseText(licenseText)}

映射中
您需要
返回
您的行。映射需要返回一些内容

const showLicenseText = () => {
 return licenseText.map(text => {
      return (<tr>
        <ThPadding>
          License Information
          {':'}
        </ThPadding>
        <td>{text}</td>
      </tr>)
  })
}
const showLicenseText=()=>{
返回licenseText.map(text=>{
返回(
许可证信息
{':'}
{text}
)
})
}

可以用
返回(等)
?不可以work@Ackman是否有任何错误?是否在
render()中定义了
showLicenseText
函数?是的,可能是这样。它是在内部定义的。我应该将其移出吗?我这样做了,也没有帮助。仍然没有什么。如果您将其移出,那么您必须使用
这个来引用它。
让我们来看看。