无法从json服务器获取嵌套的对象数组



我正试图通过json-server从一个嵌套的JSON属性fields获取对象数组,但我得到了404错误。

当我在浏览器中访问URL时'http://localhost:4001/templates/5f105f243c076f3a82c95353'我得到了db.json中提到的JSON,但当我尝试访问此URL时'http://localhost:4001/templates/5f105f243c076f3a82c95353/fields"我收到404错误。

我相信从db.json文件来看,由于fields数组是模板的一部分,所以/fields后面跟着特定模板的基本URL(http://localhost:4001/templates/5f105f243c076f3a82c95353)应该有效,但不起作用,请帮帮我。

db.json文件

{
"id": "5f105f243c076f3a82c95353",
"templateIdName": "DNIS Groups",
"templateDisplayName": "DNIS Groups Template",
"templateDescription": "Template for DNIS Groups",
"fieldCounter": 2,
"fields": [
{
"id": 1,
"fieldIdName": "OutageGroup",
"fieldDisplayName": "Outage Group",
"description": "Outage Group",
"type": "MultiList",
"values": [
{
"listValue": "2803",
"listDisplay": "Wire Down"
},
{
"listValue": "2804",
"listDisplay": "Streetlight Outage"
}
],
"initialValue": "2803",
"lockValue": "false",
"requireValue": "true",
"uniqueField": "true",
"autoFilter": "false",
"hideInList": "false",
"indexField": "true"
},
{
"id": 2,
"fieldIdName": "ProtectLinesGroups",
"fieldDisplayName": "Protect Lines Group",
"description": "Protect Lines Group",
"type": "MultiList",
"values": [
{
"listValue": "2814",
"listDisplay": "Cover Lines"
},
{
"listValue": "2815",
"listDisplay": "Voltage"
}
],
"initialValue": "2814",
"lockValue": "false",
"requireValue": "true",
"uniqueField": "false",
"autoFilter": "false",
"hideInList": "false",
"indexField": "false"
}
]
}

routes.json文件

{
"/webservice/:clientId/dblookup/template": "/templates",
"/webservice/:clientid/dblookup/template/:id": "/templates/:id",
"/webservice/:clientid/dblookup/template/:id/fields": "/templates/:id/fields"
}

实际上JSON Server没有访问嵌套资源的规定,它只能访问文件中定义为顶级属性的资源,在本例中,顶级属性将是templates,我可以使用http://localhost:4001/templates访问它,但我不能访问此处的嵌套属性values,因为http://localhost:4001/templates/2/values会导致404 not found错误。

最新更新