Ember JS FindAll returns 未定义的数据

Ember JS FindAll returns undefined data

iam 目前正在开发一个使用 ember js 作为前端的联系人管理系统网络应用程序。我正在使用 ember 商店从 api 获取数据,同时获取 json data using store.findAll() ,我正在获取具有预期数据长度的 json 数组,但是当我尝试访问 [= 中特定位置的数据时53=] array 它给出了未定义的值,它没有给出模型 value.I 已经检查了所有 like json 格式,关于我的序列化程序的命名约定 但找不到问题所在,谁能帮我解决这个问题?

应用适配器:

import RESTAdapter from '@ember-data/adapter/rest';

export default class ApplicationAdapter extends RESTAdapter {
    buildURL(...args) {
      return "http://localhost:8082/ContactManagementSystem1/api/contact/5";
    }
    headers = {
        'Accept': '*/*',
      };
}

Json 来自 api 的回复:

[
    {
        "firstName": "Example",
        "lastName": "K",
        "deletedAt": "",
        "mobileNumberHome": "7827382738",
        "companyName": "Example",
        "dateOfBirth": "2000-04-12",
        "id": 21,
        "userId": 4,
        "mobileNumberWork": "2738273788",
        "email": "rath@gmail.com"
    },
    {
        "firstName": "nameexample2",
        "lastName": "p",
        "deletedAt": "",
        "mobileNumberHome": "8989898996",
        "companyName": "Business ",
        "imageURL": "actress1.jfif",
        "dateOfBirth": "2021-10-05",
        "id": 51,
        "userId": 4,
        "mobileNumberWork": "8667889896",
        "email": "nameexample2h@gmail.com"
    }
]

序列化器:

import DS from 'ember-data';

export default DS.RESTSerializer.extend({
    normalizeResponse(store, primaryModelClass,payload,id,requestType){
        arguments[2] = {
            "contacts" : payload
        }
        return this._super(...arguments);
    }
});

由于我的 json 响应与 RestSerializer 格式不同,我在序列化程序中编写了一些代码来规范化响应。

我使用 store.findAll()

获取数据的路径
import Route from '@ember/routing/route';
import {inject as Service } from '@ember/service';
export default class UserContactRoute extends Route {
  @Service store;
  async model() {
    return this.store.findAll('contact');
  }
}

这些是我使用过的代码,我也在检查的控制台中检查过没有抛出错误,问题是模型数组对象未定义。

应该使用 objectAt(index) 来访问数组元素,因为这些数组不是常规的 JS 数组。见 here:

It's important to note that RecordArray is not a JavaScript array, it's an object that implements MutableArray. This is important because, for example, if you want to retrieve records by index, the [] notation will not work--you'll have to use objectAt(index) instead.