You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Admin调用getOne接口时提示响应数据缺少id字段的问题求助

React Admin调用getOne接口时提示响应数据缺少id字段的问题求助

大家好,我尽量把问题描述得清晰些。我正在开发一个React/Node项目,在React Admin中尝试访问资源时,遇到了如下错误提示:

The response to 'getOne' must be like { data: { id: 123, ... } }, but the received data does not have an 'id' key. The dataProvider is probably wrong for 'getOne'

我的Node后端控制器函数是这样的:

module.exports.getMovieById = async (req, res) => {
  try {
    const movie = await movieModel.findById(req.params.id);

    if (!movie) {
      return res.status(404).json({ message: "Movie not found" });
    }

    const responseData = {
      data: {
        id: movie._id.toString(),
        title: movie.title,
        position: movie.position,
        image: movie.image,
        song: movie.song.toString(),
      },
    };

    console.log('response data ', responseData)
    res.status(200).json(responseData);
  } catch (error) {
    console.error(error);
    res.status(500).json({ message: "Internal server error" });
  }
};

控制台打印的responseData如下:

response data  {
  data: {
    id: '6581bde69dcf54c00c57dc46',
    title: 'movie title',
    position: '1',
    image: 'link',
    song: '6581adf30894b8f4b251b53a'
  }
}

这份数据和我数据库里的内容一致,而且用Postman手动调用getOne接口时也能正常返回,但在React Admin里就报了这个错误。我怀疑问题出在React Admin这边,但实在找不到原因。如果需要更多细节,我可以补充提供。

备注:内容来源于stack exchange,提问作者Joe

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.20 12:00:30