이것이 쉬운 해결책이라고 생각하지만 왜 내 if 문과 관련하여 오류를 제거할 수 없는지 이해하는 데 어려움을 겪고 있습니다.
내 if 문과 관련하여 여러 구문 오류가 발생합니다. if (selectedDate < new Date().toISOString().split('T')[0]) { selectableRows: "none" }
반환(selectableRows: "none")을 추가하려고 시도했지만 내 문제도 해결되지 않았습니다.
const custom = {
customToolbar: () => <DataTableRefreshButton refresh={refresh} />,
customToolbarSelect: (selectedRows, displayData) => (
<TestToolBar
data={data}
alert={alert}
rows={rows}
type={type}
/>
),
isRowSelectable: (displayData) => {
const data= updatedStaff[
data
];
return (currentData.ActionTypeID > 0 || currentData.ActionCompletedByID > 0 ? false : true)
},
if (selectedDate < new Date().toISOString().split('T')[0]) {
selectableRows: "none"
}
};
단순화하면 다음과 같은 구조가 있습니다.
const custom = {
firstProperty: 1,
secondProperty: 'test',
if (someCondition) {
thirdProperty: 'third'
}
};
이것은 유효한 자바스크립트가 아닙니다. if
여러 문장을 작성할 때 블록 을 사용할 수 있지만 객체의 속성을 설정하는 도중에는 사용할 수 없습니다.
해당 속성에 유효한 기본값이 있는 경우 삼항 조건 연산자를 사용하여 설정할 수 있습니다.
const custom = {
customToolbar: ...
customToolbarSelect: ...
isRowSelectable: ...
selectableRows: (selectedDate < new Date().toISOString().split('T')[0]) ? 'none' : 'default'
}
그렇지 않으면 개체를 더 동적으로 빌드해야 할 수 있습니다. 다음과 같은 것:
const custom =
(selectedDate < new Date().toISOString().split('T')[0])
? { /* properties with selectableRows */ }
: { /* properties without selectableRows */ }
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다