嵌套在内存网络API中,即更长的uri

时间:2018-07-23 09:51:54

标签: angular angular-in-memory-web-api

我正在尝试使用in-memory-web-api开发应用程序,但是,我不确定如何处理更长的URI模式。

例如,我需要使用<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table class="table-responsive table-striped col-lg-12 col-md-12 col-sm-12 padding_left_right_none dash_table"> <tr> <td style="width:10px;">&nbsp;</td> <td style="width: 130px;"> <p class="name"> Name </p> <input class="text" type="text" name="name" value="<?php echo $aircrews->fname.'&nbsp;'.$aircrews->lname; ?>" style="height: 22px;width: 110px;border: none;"> </td> <td style="width: 40px;"> <p class="name"> name </p> <input type="text" class="text" name="pay1" value="<?php echo $aircrews->pay_status1; ?>" style="height: 22px;width: 20px;border: none;text-align: center;"> </td> <td style="width: 40px;"> <p class="name"> name </p> <input type="text" class="text" name="pay2" value="<?php echo $aircrews->pay_status2; ?>" style="height: 22px;width: 20px;border: none;text-align: center;"> </td> <td class="right_set"><button class="edit_btn">Edit / -</button></td> </tr> </table>/api/v1/configuration/manager从服务器获取一些配置数据。我的虚拟数据结构如下:

/api/v1/configuration/customer

但是我404错误。这是我形成GET请求的方式:

const v1 = [{
  configuration: {
    manager: [{...}, {...}, ...],
    customer: [{...}, {...}, ...]
  }
}];

想法是在开发过程中尽可能以角度映射我的API。我该如何处理这种嵌套数据和URI?

1 个答案:

答案 0 :(得分:1)

看来angular-in-memory-web-api模块不是为这种情况而设计的。作为旁路,请尝试以下操作:

  1. 您的apiBase应该是api
  2. 数组v1中的项目应具有属性id = 'configuration/*'
createDb() {
  const v1 = [
    {
      id: 'configuration/manager',
      data: [{...}, {...}, ...]
    },
    {
      id: 'configuration/customer',
      data: [{...}, {...}, ...]
    }
  ];

  return { v1 };
}