简体   繁体   中英

Customising the API mapping for ng-admin, need a function to change “id” to “_id”

Currently I am using ng-admin to build an admin panel for my webapp.

http://ng-admin-book.marmelab.com/doc/API-mapping.html

This link talks about API mapping and the JSON response expected when ng-admin uses a GET request to get data.

The JSON response format is as follows:

{
  "id": 12,
  "name": "War and Peace",
  "author_id": 345,
  "publication_date": "2014-01-01T00:00:00Z",
}

for a book entity defined by name, author_id and publication date.

My REST API returns exactly the same except "_id" instead of "id".

I think this is the reason I can't retrieve data from my API. How can I solve this issue?

Use the entity identifier() method, as explained in the doc ( http://ng-admin-book.marmelab.com/doc/API-mapping.html ):

var post = nga.entity('posts')
  .identifier(nga.field('_id'));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM