I have a Web API returning to an Ember app the JSON above:
[
{
"id": 1,
"title": "Test",
"link": "index",
"isActive": false,
"children": [
{
"id": 4,
"title": "Test 2",
"link": "index",
"isActive": false
}
]
},
{
"id": 2,
"title": "Test 3",
"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
}
]
}
]
When I try to call "findAll" method in Ember, it is listing the children menus as they are in root:
model() {
return this.get('store').findAll('menu').then(function(menus){
menus.forEach(function (item, index, enumerable) {
console.log(item.get('title'));
});
});
}
Console result:
Test 2
Test 4
Test 6
Test 7
Test
Test 3
Test 5
I want to bring just the root elements: "Test", "Test 3" and "Test 5". The rest will be in children attribute of the corresponding parent. Here is my "menu.js"
import DS from 'ember-data';
export default DS.Model.extend({
title: DS.attr('string'),
link: DS.attr('string'),
isActive: DS.attr('boolean'),
icon: DS.attr('string'),
children: DS.hasMany('menu', { inverse: null })
});
Aucun commentaire:
Enregistrer un commentaire