reactjs - 反应处理 api 参数未显示
问题描述
这是我的专栏。
我需要来自 api 的包含客户 ID 的 href。我目前正在使用 reactTable,一切正常。但是当我查看控制台内部时,只有参数没有被处理。谁能告诉我缺少什么?
const columns = [
{
Header: '',
accessor: 'links[0].href',
filterable: false,
sortable: false,
Cell: ({params}) => <Button color="secondary" onClick={()=>deleteCustomer(params)}>Delete</Button>
}
];
const deleteCustomer = (params) => {
console.log(params)
};
const getCustomer = () => {
fetch('https://customerrest.herokuapp.com/api/customers')
.then(response => response.json())
.then(data => setCustomer(data.content))
.catch(err => console.error(err))
};
这是一个示例 API 调用:
{
"links" : [ {
"rel" : "self",
"href" : "https://customerrest.herokuapp.com/api/customers"
}, {
"rel" : "profile",
"href" : "https://customerrest.herokuapp.com/api/profile/customers"
} ],
"content" : [ {
"firstname" : "Mark",
"lastname" : "Johnson",
"streetaddress" : "5th Street",
"postcode" : "23110",
"city" : "Flintsone",
"email" : "john@mail.com",
"phone" : "232-2345540",
"content" : [ ],
"links" : [ {
"rel" : "self",
"href" : "https://customerrest.herokuapp.com/api/customers/620"
}, {
"rel" : "customer",
"href" : "https://customerrest.herokuapp.com/api/customers/620"
}, {
"rel" : "trainings",
"href" : "https://customerrest.herokuapp.com/api/customers/620/trainings"
} ]
}
解决方案
在您的 onClick 句柄函数中传递参数:
Cell: ({params}) => <Button color="secondary" onClick={(params)=>deleteCustomer(params)}>Delete</Button>
推荐阅读
- vba - Email body format changed for some recipients VBA
- java - How to build Objects for class that has fields annotated with @XmlAnyElement and takes list of Objects
- f# - Conditional compiling not work with F#/Visual Studio Mac with shared assembly (how workaround)
- angularjs - How do I toggle a class for only one reused (but not repeated) element in Angular 1?
- php - What is a host server
- vba - Avaya CMS 报告到 excel vba
- javascript - 谷歌浏览器削减通知标题
- objective-c - iPhone UI 测试 - 如何访问键盘上的删除键
- c# - 如何在 .pptx /.pptm 中使用自定义 Xml / 用户定义的标签,以便 PowerPoint 2013 不会擦除它?
- javascript - 对启用了选择的 antd (Ant Design) 表进行排序