Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.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 我想重定向一个带有get api id onclick按钮的页面,该按钮位于引导表2中_Reactjs_Redirect_Datatable_Get_React Bootstrap Table - Fatal编程技术网

Reactjs 我想重定向一个带有get api id onclick按钮的页面,该按钮位于引导表2中

Reactjs 我想重定向一个带有get api id onclick按钮的页面,该按钮位于引导表2中,reactjs,redirect,datatable,get,react-bootstrap-table,Reactjs,Redirect,Datatable,Get,React Bootstrap Table,[![enter image description here][1][1]我使用表中的编辑图标重定向页面并编辑数据。但是我试图通过传递我认为这个ID为表的NoMovivOffice ID来重定向一个页面,但是我不知道如何通过传递ID。表名作为位置。所有的数据都在那里。 GETAPI中有以下数据结构 [ { Nomovi_LocationId: "92f05a02-956a-4adf-8dba-16d2161e0deb", Locati

[![enter image description here][1][1]我使用表中的编辑图标重定向页面并编辑数据。但是我试图通过传递我认为这个ID为表的NoMovivOffice ID来重定向一个页面,但是我不知道如何通过传递ID。表名作为位置。所有的数据都在那里。

GETAPI中有以下数据结构

[
    {
        Nomovi_LocationId: "92f05a02-956a-4adf-8dba-16d2161e0deb",
        LocationName: "Athens",
        Delete_Flag: 1,
        Created: "2020-02-21T20:34:19.337",
        CreatedBy: null,
        Modified: "2020-02-21T20:34:19.337",
        ModifiedBy: null,
    },
];
var userid=“8f0d0f73-8d52-468b-9844-16d30d303f57”;
var sessionid=“5d90bc03-d7b3-4bbb-974e-e379c52b147a”;
类LocationInventory扩展组件{
建造师(道具){
超级(道具);
此.state={
地点:[],
};
}
componentDidMount(){
var getLocationapi=
"https://nomovi365-api.azurewebsites.net/api/" +
“地点”+
"/" +
用户ID+
"/" +
会话ID;
获取(getLocationapi{
方法:“获取”,
})
.then((response)=>response.json())
。然后((位置)=>{
this.setState({location:location});
});
}
editRow(e,Nomovi_LocationId){
window.location.href=“EditLocation?LocationId=“+Nomovi_LocationId+”/”;
e、 停止传播();
}
render(){
常数位置=[
{
类:“自定义单元格”,
格式化程序:(单元格)=>{
返回(
);
},
头型:(colum,colIndex)=>{
返回{width:“60px”};
},
tdStyle:{空白:“正常”,换行字:“断字”},
},
{
类:“自定义单元格”,
格式化程序:(单元格)=>{
返回(
);
},
头型:(colum,colIndex)=>{
返回{width:“60px”};
},
tdStyle:{空白:“正常”,换行字:“断字”},
},
{
数据字段:“LocationName”,
文本:“位置名称”,
头型:(colum,colIndex)=>{
返回{width:“300px”};
},
tdStyle:{空白:“正常”,换行字:“断字”},
},
{
数据字段:“已创建”,
文本:“已创建”,
格式化程序:(单元格)=>{
如果(!单元格){
返回“”;
}
返回`${
力矩(单元格)。格式(“DD-MM-YYY”)
?力矩(单元格)。格式(“MM/DD/YYYY”)
:力矩(单元格).格式(“MM/DD/YYYY”)
}`;
},
tdStyle:{空白:“正常”,换行字:“断字”},
},
{
数据字段:“CreatedBy”,
文本:“CreatedBy”,
tdStyle:{空白:“正常”,换行字:“断字”},
},
{
数据字段:“已修改”,
文本:“修改”,
格式化程序:(单元格)=>{
如果(!单元格){
返回“”;
}
返回`${
力矩(单元格)。格式(“DD-MM-YYY”)
?力矩(单元格)。格式(“MM/DD/YYYY”)
:力矩(单元格).格式(“MM/DD/YYYY”)
}`;
},
tdStyle:{空白:“正常”,换行字:“断字”},
},
{
数据字段:“ModifiedBy”,
文本:“修改过”,
tdStyle:{空白:“正常”,换行字:“断字”},
},
];
返回(
);
}
}
请检查此项。只需映射上面链接中提到的来自服务器的响应。并将此行添加到TableCell

this.editRow(this.state.location.Nomovi\u LocationId)}>Edit

请将您的editRow函数更改为这个
editRow(Nomovi\u LocationId)
。现在,您正在将每一行的id传递给editRow函数,该函数将与id一起重定向到编辑页面。我希望这会起作用

此外,您也可以不使用任何组件来执行此操作。请看下面的示例代码

var userid = "8f0d0f73-8d52-468b-9844-16d30d303f57";
var sessionid = "5d90bc03-d7b3-4bbb-974e-e379c52b147a";

class LocationInventory extends Component {
    constructor(props) {
        super(props);
        this.state = {
            location: [],
        };
    }

render(){
return(
<table className='table'>
   <thead>
      <tr>
          <th>
              //Your table Heading goes here
          </th>
      </tr>
      <tbody>
          { this.state.location.map((data, index) => {
              <tr> 
                    <td><button onClick={() => this.editRow(this.state.location.Nomovi_LocationId)}>Edit</button></td>
             
                    <td>data.LocationName</td>
                    <td>rest of your table data goes here .....</td>
               </tr>
           })}
       </tbody>
   </thead>
</table>
)
}
}
var userid=“8f0d0f73-8d52-468b-9844-16d30d303f57”;
var sessionid=“5d90bc03-d7b3-4bbb-974e-e379c52b147a”;
类LocationInventory扩展组件{
建造师(道具){
超级(道具);
此.state={
地点:[],
};
}
render(){
返回(
//你的桌头在这里
{this.state.location.map((数据,索引)=>{
this.editRow(this.state.location.Nomovi_LocationId)}>Edit
data.LocationName
表中的其余数据都放在这里。。。。。
})}
)
}
}

试试这个,看看。。。让我知道它是否有效。

我正在努力理解您的问题,如果我错了,请纠正我。在带有编辑按钮的表中有一组记录,当您单击编辑按钮时,它必须传递id,以便您可以编辑属于该特定id的记录,对吗?我可以看到您的
editRow
函数接受2个参数,并且您正在使用onClick侦听器调用该函数。问题是您没有将id作为参数传递给该函数,例如:onClick={()=>this.editRow(id在这里)}。请让我知道它是否有效。请将editRow函数更改为