Javascript 从数组中呈现表行:react
我试图调用一个函数,在作为道具接收的文本数组上使用map函数渲染表行,但由于某些原因,它们没有被渲染。我是否犯了语法错误?我已经验证了许可证文本道具数组不是空的,只是返回一个字符串数组Javascript 从数组中呈现表行:react,javascript,reactjs,react-native,jsx,Javascript,Reactjs,React Native,Jsx,我试图调用一个函数,在作为道具接收的文本数组上使用map函数渲染表行,但由于某些原因,它们没有被渲染。我是否犯了语法错误?我已经验证了许可证文本道具数组不是空的,只是返回一个字符串数组 const showLicenseText = () => { return licenseText.map(text => { <tr> <ThPadding> License Information {'
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
函数?是的,可能是这样。它是在内部定义的。我应该将其移出吗?我这样做了,也没有帮助。仍然没有什么。如果您将其移出,那么您必须使用这个来引用它。
让我们来看看。