React의 구성 요소에서 render () 메서드 내부의 JavaScript에서 unshift 메서드를 사용하고 있으며 이제 배열 크기가 페이지에 표시됩니다. 크기를 반환하지 않고 처음에 요소를 넣는 방법이 JavaScript에 있습니까?
render() {
let cells = [];
code.....
return (
<div>
<Table padding="dense">
<TableHead>
<TableRow className="compact" color="dark">
{code...}
{
cells.unshift({ style: {}, fieldName: fieldNames.substr(3), extraOptions: {} })
}
{
cells.map(cell => {
return <TableCell style={cell.style} key={`${cell.fieldName}`} {...cell.extraOptions}>{cell.fieldName}</TableCell>;
})
}
</TableRow>
</TableHead>
....
@Brian Thompson이 말했듯이 JSX 외부로 논리를 옮겼습니다.
render() {
let cells = [];
code.....
{
cells.unshift({ style: {}, fieldName: fieldNames.substr(3), extraOptions: {} })
}
return (
<div>
<Table padding="dense">
<TableHead>
<TableRow className="compact" color="dark">
{
cells.map(cell => {
return <TableCell style={cell.style} key={`${cell.fieldName}`} {...cell.extraOptions}>{cell.fieldName}</TableCell>;
})
}
</TableRow>
</TableHead>
....
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다