Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.3k views
in Technique[技术] by (71.8m points)

reactjs - pass props from multiple arrays in state

I want to be able to map over too arrays, specifically the elementstomap array and the sortedScheduleData. As I am trying to pass props from both of those arrays into a component I want to be able to pass both sortedScheduleData and elementsToMap into the scheduleDataRow Component, just unsure how to do this. Much help would be appreciated!

I have removed code to make it easier to read

const schedules = () => {
 
  const [scheduleData, setScheduleData] = useState([])
  const [showScheduleModal, setShowScheduleModal] = useState(false)
  const [scheduleFieldData, setScheduleFieldData] = useState({})


  const sortedScheduleData = [].concat(scheduleData)
    .sort((a, b) => a.id < b.id ? 1 : -1)

  const elementsToMap = mapping.elements.filter(e => e.type === mapping.elementType).sort((x, y)=> mapping.sortElements(x, y))


  return (!scheduleData ? null :
    <PageWrapper title='Schedules'>

      <div style={{marginBottom: '20px'}}>
        <Button
          onClick={showModal}
          className='Button Dark Main'
          text='CREATE SCHEDULE'
        />
      </div>

      <div className='Card'>
        <div className='TableTopbar ScheduleGrid'>
          <div>ID</div>
          <div>Interval</div>
          <div>Project ID</div>
          <div>Database</div>
          <div>Create Timestamp</div>
          <div>Create User Id</div>
          <div>Edit</div>
        </div>

        {sortedScheduleData.map(schedule =>
          <ScheduleDataRow
            key={schedule.id}
            schedule={schedule}
            setScheduleData={setScheduleData}
            onScheduleFieldUpdate={onScheduleFieldUpdate}
            setScheduleFieldData={setScheduleFieldData}
            scheduleFieldData={scheduleFieldData}
            onDatabaseSelect={onDatabaseSelect}

          />
        )}
      </div>

      <ScheduleModal
        showScheduleModal={showScheduleModal}
        onCloseScheduleModal={onCloseScheduleModal}
        onScheduleFieldUpdate={onScheduleFieldUpdate}
        scheduleFieldData={scheduleFieldData}
        onSubmitTestingScheduleClick={onSubmitTestingScheduleClick}
        scheduleFieldData={scheduleFieldData}
        // onFieldUpdate={onFieldUpdate}
        onDatabaseSelect={onDatabaseSelect}
        database={database}
       />

    </PageWrapper>
  )
}

export default schedules

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...