@fsamorodov

Как оформить ответ с сервера через JSONAPIAdapter в Emberjs?

Насколько я понял, этот адаптер использует JSONAPISerializer.
Такая ли будет структура у ответа с сервера как в примере?

// models/report.js  - отчеты
 export default DS.Model.extend({
     date: attr('string'),
     lists: hasMany('report-list', {
         async: true
     }),
     is_sending: attr('boolean'),
     status: attr('string'),
     checks: attr('number'),
     acquiring: attr('string'),
     cash: attr('string'),
     sent_at: attr('string'),
     status_title: attr('string')
 });

 // models/report-list.js - статьи расходов в отчете

 export default DS.Model.extend({
     summ: DS.attr('string'),
     unit: DS.belongsTo('financial-item', {
         async: true
     }),
     comment: DS.attr('string')
 });

// financial-items  - справочник статей
 export default DS.Model.extend({
     title: DS.attr('string'),
     description: DS.attr('string')
 });

 { //загружаем отчеты   api/reports GET
     "data": [{
         "id": "1",
         "type": "reports",
         "attributes": {
             "date": "21 декабря 2015",
             "is_sending": "true",
             "status": "success",
             "checks": "245",
             "acquiring": "245.00",
             "cash": "1234.00",
             "sent_at": "15:20",
             "status_title": "Отправлено"
         },
         "relationships": {
             "lists": {
                 "data": [{
                     "id": "1",
                     "type": "repost-lists"
                 }]
             }
         }

     }],
     "included": [{
             "id": "1",
             "attributes": {
                 "summ": "23",
                 "comment": "Дал зп"
             },

             "relationships": {
                 "unit": {
                     "data": [{
                         "id": "1",
                         "type": "financial-items"
                     }],
                     "included": [{
                         "id": "1",
                         "attributes": {
                             "title": "1 статья",
                             "description": "Расходы по банку"
                         },
                         "type": "financial-items"
                     }]
                 }
             },
             "type": "report-lists"
     }]
 }
  • Вопрос задан
  • 97 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы