我正在尝试使用 ArrayController 来处理显示一些将在用户点击时换出的数据。我目前收到此错误,Uncaught Error: Assertion Failed: The value that #each loops over must be an Array. You passed App.CurrentListController
但如果我查看 Ember Inspector,我可以看到 CurrentListController,其中包含模型和数据。基本上,统计页面可以让您看到一堆统计数据,然后单击特定统计数据会弹出一个模式并显示与该统计数据相关的所有记录。如果我只是将记录存储在 StatController 上,它可以正常工作,但是我无法使用 ArrayController 进行排序/过滤。所以这一切都有效,除了当我尝试显示 CurrentListController 的内容时它吓坏了。
感谢您的任何帮助或指导。
当前列表控制器:
App.CurrentListController = Ember.ArrayController.extend({
sortProperties: ['name'], //Initial sort column.
sortAscending: true,
});
统计控制器:
App.StatController = Ember.ObjectController.extend({
needs:['currentList'],
currentList:[],
actions: {
viewBusiness: function(ids) {
console.log(ids)
var self = this
console.log(this.get('controllers.currentList').get('sortProperties'))
this.store.findByIds('business', ids.split(",")).then(
function(results)
{
$('#editModal').modal('show');
//self.set('currentList', results.sortBy(["name"]))
self.get('controllers.currentList').set('model', results)
console.log(self.get('controllers.currentList').get('arrangedContent'))
});
},
sortBy: function(prop){
var clController = this.get('controllers.currentList')
clController.set('sortProperties', prop)
clController.set('sortAscending', !clController.get('sortAscending'));
}
}
});
统计模板:
{{#each business in App.CurrentListController}}
<tr {{bind-attr id=business.id}}>
<td>{{business.name}}</td>
<td>{{business.city}}</td>
<td>{{business.state}}</td>
<td>{{business.zip}}</td>
<td class="text-center">{{business.numVendors}}{{/link-to}}</td>
<td class="text-center">{{business.numClients}}{{/link-to}}</td>
</tr>
{{/each}}