【发布时间】:2017-12-31 02:24:19
【问题描述】:
我想在 CRUD 响应烤面包机中添加服务器响应消息。例如,当我们进行更新时,我们将收到“元素更新”的烤面包机消息。而不是它,我想显示一些动态(非静态)服务器响应的消息。
【问题讨论】:
标签: admin-on-rest
我想在 CRUD 响应烤面包机中添加服务器响应消息。例如,当我们进行更新时,我们将收到“元素更新”的烤面包机消息。而不是它,我想显示一些动态(非静态)服务器响应的消息。
【问题讨论】:
标签: admin-on-rest
目前仅支持错误消息。如果这真的很重要,请提出功能请求,我们会考虑。
【讨论】:
执行此操作的方法有点冗长。但绝对有可能。
1) 编写一个自定义的 restWrapper 或 RestClient https://marmelab.com/admin-on-rest/RestClients.html
2) 如下处理请求和响应。
function handleRequestAndResponse(url, options={}, showAlert={}) {
return fetchUtils.fetchJson(url, options)
.then((response) => {
const {headers, json} = response;
//admin on rest needs the {data} key
const data = {data: json}
if (headers.get('x-total-count')) {
data.total = parseInt(headers.get('x-total-count').split('/').pop(), 10)
}
// handle get_list responses
if (!isNaN(parseInt(headers.get('x-total-count'), 10))) {
return {data: json,
total: parseInt(headers.get('x-total-count').split('/').pop(), 10)}
} else {
return data
}
})
}
3) 现在您的代码中有一个位置可以截取来自服务器的数据。在上面的代码中,您可以在需要时定义和拍摄包含您的数据的动作。创建一个reducer,它从您的操作中获取数据并在您可以称之为通知的状态下填充一个字段。
4) 使用 redux-saga 选择方法 How to get something from the state / store inside a redux-saga function?
您现在可以访问商店中的通知数据,并将自定义烤面包机消息显示到您心中的内容:)
【讨论】: