gpt4 book ai didi

javascript - 尝试在 ember.js 中 self 引用模型时出错

转载 作者:行者123 更新时间:2023-11-30 15:24:55 25 4
gpt4 key购买 nike

我正在尝试在模型中创建自引用属性,但出现以下错误:

Error while processing route: index No model was found for 'menu' Error

这是我的模型(menus.js):

import DS from 'ember-data';

export default DS.Model.extend({
title: DS.attr('string'),
link: DS.attr('string'),
isActive: DS.attr('boolean'),
children: DS.hasMany('menus', { inverse: null }),
});

我正在尝试从 Web API 返回一个列表。这是我的 API JSON 返回:

[
{
"id": 1,
"title": "Test",
"link": "index",
"isActive": false,
"children": [
{
"id": 4,
"title": "Test 2",
"link": "index",
"isActive": false
}
]
},
{
"id": 2,
"title": "Test 2",
"link": "index",
"isActive": false,
"children": [
{
"id": 5,
"title": "Test 4 ",
"link": "index",
"isActive": false
}
]
},
{
"id": 3,
"title": "Test 5",
"link": "index",
"isActive": false,
"children": [
{
"id": 6,
"title": "Test 6",
"link": "index",
"isActive": false
},
{
"id": 7,
"title": "Test 7",
"link": "index",
"isActive": false
}
]
}
]

最佳答案

您应该以单数形式调用您的模型。因此,将 model/menus.js 重命名为 model/menu.jsDS.hasMany('menus', { inverse: null }),使用 DS.hasMany('menu', { inverse: null }),

关于javascript - 尝试在 ember.js 中 self 引用模型时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43149383/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com