Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.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
Reactjs 如何使表格行可点击? 从“React”导入React 导入“./myform.css” 常量Emp=()=>{ 康斯特球员=[ { id:1, 全名:“员工1”, 电邮:'example1@mail.com', 加入日期:2020年8月5日, }, { id:2, 全名:'Employee 2', 电邮:'example2@mail.com', }, { id:3, 全名:'Employee 3', 电邮:'example3@mail.com', 加入日期:2020年8月10日 }, { id:4, 全名:'Employee 4', 电邮:'example4@mail.com', 加入日期:2020年8月5日 }, ] /*我想让行可点击,当它点击信息 从整行显示在另一页上 我试着让行可点击,但失败了, 我收到错误“rowSelect()未定义!!!”*/ 行选择=(事件)=>{ console.log(事件); } 常量renderPlayer=(玩家,索引)=>{ 报税表( {player.id} {player.fullName} {player.email} {player.joiningdate} ) } >//在UI上将数据返回为表格式 返回( 身份证件 全名 电子邮件 加入日期 {players.map(renderPlayer)} ) } 导出默认Emp_Reactjs - Fatal编程技术网

Reactjs 如何使表格行可点击? 从“React”导入React 导入“./myform.css” 常量Emp=()=>{ 康斯特球员=[ { id:1, 全名:“员工1”, 电邮:'example1@mail.com', 加入日期:2020年8月5日, }, { id:2, 全名:'Employee 2', 电邮:'example2@mail.com', }, { id:3, 全名:'Employee 3', 电邮:'example3@mail.com', 加入日期:2020年8月10日 }, { id:4, 全名:'Employee 4', 电邮:'example4@mail.com', 加入日期:2020年8月5日 }, ] /*我想让行可点击,当它点击信息 从整行显示在另一页上 我试着让行可点击,但失败了, 我收到错误“rowSelect()未定义!!!”*/ 行选择=(事件)=>{ console.log(事件); } 常量renderPlayer=(玩家,索引)=>{ 报税表( {player.id} {player.fullName} {player.email} {player.joiningdate} ) } >//在UI上将数据返回为表格式 返回( 身份证件 全名 电子邮件 加入日期 {players.map(renderPlayer)} ) } 导出默认Emp

Reactjs 如何使表格行可点击? 从“React”导入React 导入“./myform.css” 常量Emp=()=>{ 康斯特球员=[ { id:1, 全名:“员工1”, 电邮:'example1@mail.com', 加入日期:2020年8月5日, }, { id:2, 全名:'Employee 2', 电邮:'example2@mail.com', }, { id:3, 全名:'Employee 3', 电邮:'example3@mail.com', 加入日期:2020年8月10日 }, { id:4, 全名:'Employee 4', 电邮:'example4@mail.com', 加入日期:2020年8月5日 }, ] /*我想让行可点击,当它点击信息 从整行显示在另一页上 我试着让行可点击,但失败了, 我收到错误“rowSelect()未定义!!!”*/ 行选择=(事件)=>{ console.log(事件); } 常量renderPlayer=(玩家,索引)=>{ 报税表( {player.id} {player.fullName} {player.email} {player.joiningdate} ) } >//在UI上将数据返回为表格式 返回( 身份证件 全名 电子邮件 加入日期 {players.map(renderPlayer)} ) } 导出默认Emp,reactjs,Reactjs,由于这是一个功能组件,您需要将函数声明为 import React from 'react' import './myform.css' const Emp=()=>{ const players=[ { id: 1, fullName: 'Employee 1', email:'example1@mail.com', joiningdate: '05/08/2020',

由于这是一个功能组件,您需要将函数声明为

import React from 'react'
import './myform.css'

const Emp=()=>{
 const players=[
        {
            id: 1,
            fullName: 'Employee 1',
            email:'example1@mail.com',
            joiningdate: '05/08/2020',
            
        },
        {
            id: 2,
            fullName: 'Employee 2',
            email:'example2@mail.com',
         },
        {
            id: 3,
            fullName: 'Employee 3',
            email:'example3@mail.com',
            joiningdate: '10/08/2020'
        },
        {
            id: 4,
            fullName: 'Employee 4',
            email:'example4@mail.com',
            joiningdate: '05/08/2020'
        },

    ]

/* I want to make row clickable and when it clicked information 
from whole row is display on other page
I trying so much to make row clickable but it fails, 
I got error "rowSelect() is undefined!!!" */

    rowSelect=(event)=>{
      console.log(event);
    }    
     
    const renderPlayer=(player, index)=>{            
            return(                
                <tr key={index} onClick={this.rowSelect}>
                    <td>{player.id}</td>
                    <td>{player.fullName}</td>
                    <td>{player.email}</td>
                    <td>{player.joiningdate}</td>
                </tr>
            )
        }        
    
    > //return data into table format on UI
    
        return(
            <div className='emp'>
                <table className='border'>
                    <thead>
                        <tr >
                            <th>Id</th>
                            <th>Full Name</th>
                            <th>Email</th>
                            <th>Joining Date</th>
                        </tr>
                    </thead>
                    <tbody>
                        {players.map(renderPlayer)}
                    </tbody>
                </table>
            </div>
        )
    }    
    export default Emp

然后像这样把它放在你的鼠标上

const rowSelect = event => {
}

由于这是一个功能组件,您需要将函数声明为

import React from 'react'
import './myform.css'

const Emp=()=>{
 const players=[
        {
            id: 1,
            fullName: 'Employee 1',
            email:'example1@mail.com',
            joiningdate: '05/08/2020',
            
        },
        {
            id: 2,
            fullName: 'Employee 2',
            email:'example2@mail.com',
         },
        {
            id: 3,
            fullName: 'Employee 3',
            email:'example3@mail.com',
            joiningdate: '10/08/2020'
        },
        {
            id: 4,
            fullName: 'Employee 4',
            email:'example4@mail.com',
            joiningdate: '05/08/2020'
        },

    ]

/* I want to make row clickable and when it clicked information 
from whole row is display on other page
I trying so much to make row clickable but it fails, 
I got error "rowSelect() is undefined!!!" */

    rowSelect=(event)=>{
      console.log(event);
    }    
     
    const renderPlayer=(player, index)=>{            
            return(                
                <tr key={index} onClick={this.rowSelect}>
                    <td>{player.id}</td>
                    <td>{player.fullName}</td>
                    <td>{player.email}</td>
                    <td>{player.joiningdate}</td>
                </tr>
            )
        }        
    
    > //return data into table format on UI
    
        return(
            <div className='emp'>
                <table className='border'>
                    <thead>
                        <tr >
                            <th>Id</th>
                            <th>Full Name</th>
                            <th>Email</th>
                            <th>Joining Date</th>
                        </tr>
                    </thead>
                    <tbody>
                        {players.map(renderPlayer)}
                    </tbody>
                </table>
            </div>
        )
    }    
    export default Emp

然后像这样把它放在你的鼠标上

const rowSelect = event => {
}


只需添加onClick处理程序:
console.log('ima handler')}/>
只需添加onClick处理程序:
console.log('ima handler')}/>
但行中的数据不会在控制台中打印我们如何在单击时在控制台中打印行中的数据?但行中的数据不会在控制台中打印我们如何在单击时在控制台中打印行中的数据?