Ember.js:如何从Ember.Map查看数据
我想查看一些按部门分组的联系信息(姓名、电子邮件等),但我无法使用手柄实现Ember.js:如何从Ember.Map查看数据,ember.js,handlebars.js,nested-loops,Ember.js,Handlebars.js,Nested Loops,我想查看一些按部门分组的联系信息(姓名、电子邮件等),但我无法使用手柄实现 第十部门 联系方式x1信息 联系信息 Y系 联系y1信息 联系y2信息 我不知道我提前有多少个部门。因此,在我的控制器中,我尝试在一个Ember.Map中加载信息,其中部门是它的键,而带有联系人信息的数组是每个部门的值。是这样的: map = Ember.Map.create(); // Load data from server into map // m = {'Department X': [{na
- 第十部门
- 联系方式x1信息
- 联系信息
- Y系
- 联系y1信息
- 联系y2信息
map = Ember.Map.create();
// Load data from server into map
// m = {'Department X': [{name:'x1','email':'emailx1',...},{...}], 'Department Y':[....], ...}
{{#each department in map}}
{{department}}
{{#each contact in map.keys}}
{{contact.name}} | {{contact.email}}
{{#each}}
{{#each}}
App.Department = Ember.Object.extend({
name: null
contacts: null // will be an array of App.Contact
})
App.Contact = Ember.Object.extend({
name: null,
email: null,
})
抛出一个错误,说明“EmberCollectionView的内容必须实现Ember.Array。您传递了[object]”。是否可以使用嵌套数据实现suh任务?欢迎任何帮助。谢谢。像这样创建一个Department类怎么样:
map = Ember.Map.create();
// Load data from server into map
// m = {'Department X': [{name:'x1','email':'emailx1',...},{...}], 'Department Y':[....], ...}
{{#each department in map}}
{{department}}
{{#each contact in map.keys}}
{{contact.name}} | {{contact.email}}
{{#each}}
{{#each}}
App.Department = Ember.Object.extend({
name: null
contacts: null // will be an array of App.Contact
})
App.Contact = Ember.Object.extend({
name: null,
email: null,
})
还有一个像这样的联系人类:
map = Ember.Map.create();
// Load data from server into map
// m = {'Department X': [{name:'x1','email':'emailx1',...},{...}], 'Department Y':[....], ...}
{{#each department in map}}
{{department}}
{{#each contact in map.keys}}
{{contact.name}} | {{contact.email}}
{{#each}}
{{#each}}
App.Department = Ember.Object.extend({
name: null
contacts: null // will be an array of App.Contact
})
App.Contact = Ember.Object.extend({
name: null,
email: null,
})
加载数据时,您可以简单地构建一个部门数组
App.departments = [];
// parse the arriving json and populate the departments array
App.departments.pushObject(
App.Department.create(
{name: dptLoadedName, contacts: [App.Contact.create({...})]}
)
)
因此,在模板中,您可以执行以下操作:
{{#each department in App.departments}}
{{department.name}}
{{#each contact in department.contacts}}
{{contact.name}} | {{contact.email}}
{{#each}}
{{#each}}
完美的在等待答案的时候,我正是这样做的,而且效果非常好。我试图使用Ember.Map,因为我来自JavaUniverse,我曾经在模板中使用Map来完成这样的任务。万分感谢