【发布时间】:2017-04-05 04:24:23
【问题描述】:
我有一个 Web API 将上面的 JSON 返回给 Ember 应用程序:
[
{
"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
}
]
}
]
当我尝试在 Ember 中调用“findAll”方法时,它会列出根目录中的子菜单:
model() {
return this.get('store').findAll('menu').then(function(menus){
menus.forEach(function (item, index, enumerable) {
console.log(item.get('title'));
});
});
}
控制台结果:
Test 2
Test 4
Test 6
Test 7
Test
Test 3
Test 5
我只想带上根元素:“Test”、“Test 3”和“Test 5”。其余的将在相应父项的子项属性中。这是我的“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 })
});
【问题讨论】:
标签: c# json asp.net-web-api ember.js asp.net-core