在有效负载中遇到“类别”,但未找到模型名称“类别”

时间:2017-12-11 19:35:08

标签: ember.js ember-data ember-cli

当我尝试从REST API加载类别产品时,我在“有效负载”中收到此警告“遇到”类别,但未找到模型名称“类别”的模型(已解析的模型名称使用(未知mixin).modelNameFromPayloadKey(“类别“))”和数据不打印。

我从API获得的数据: -

{
    "categories": [{
        "id": 6737,
        "category_id": 1,
        "product_id": 3954,
        "product": {
            "id": 3954,
            "seller_id": null,
            "sku": "UN1185",
            "product": "Party",
            "description2": "Disclaimer: ",
            "mrp": 795,
            "price": 1499,
            "off": "75",
            "stock": 1,
            "total_products": 5,
            "catalogType": null,
            "weight": "1",
            "delivered_in": null,
            "chart_id": null,
            "stitching": 0,
            "seo_title": "Buy Now Party wear Light Peach Khadi Art Silk Plain Saree",
            "seo_description": "Shop",
            "keyword": "saree",
            "position": 1503,
            "status": 1,
            "product_images": [{
                "product_id": 3954,
                "url": "UN1185.jpg"
            }]
        }
    }, {
        "id": 6735,
        "category_id": 1,
        "product_id": 3953,
        "product": {
            "id": 3953,
            "seller_id": null,
            "sku": "UN1933",
            "product": "Party wear Pink Khadi Art Silk Plain Saree",
            "slug": "party-wear-pink-khadi-art-silk-plain-saree-un1933",
            "description": "Party wear Pink Khad..",
            "description2": "Disclaimer",
            "mrp": 795,
            "price": 1499,
            "off": "75",
            "stock": 1,
            "total_products": 4,
            "catalogType": null,
            "weight": "1",
            "delivered_in": null,
            "chart_id": null,
            "stitching": 0,
            "seo_title": "Buy Now Party",
            "seo_keyword": "saree",
            "keyword": "saree ",
            "position": 1503,
            "status": 1,
            "product_images": [{
                "product_id": 3953,
                "url": "UN1933.jpg"
            }]
        }
    }],
    "paging": {
        "prevPage": false,
        "nextPage": true,
        "currentPage": 1,
        "resultCount": 22
    }
}

我的categories.js序列化程序

import DS from 'ember-data';

export default DS.RESTSerializer.extend({
    normalizeResponse(store, primaryModelClass, payload, id, requestType) {
        //console.log(payload.categories);
        payload = {
            categories: payload.categories
        };

        //console.log(payload);
        return this._super(store, primaryModelClass, payload, id, requestType);
    }
});

当我查看类别页面时,我收到警告并且没有打印任何数据

WARNING: Encountered "categories" in payload, but no model was found for model name "category" (resolved model name using (unknown mixin).modelNameFromPayloadKey("categories"))

1 个答案:

答案 0 :(得分:0)

您似乎只为category模型编写了特定的序列化程序。所以请确保您具有以下内容,并且其文件名与型号名称相同。

app/models/category.js
app/serializers/category.js