我正在尝试使用ArrayController来处理显示一些将在用户点击时交换的数据。我目前收到此错误,Uncaught Error: Assertion Failed: The value that #each loops over must be an Array. You passed App.CurrentListController
但是如果我查看Ember Inspector,我可以看到CurrentListController,其中包含模型和数据。 基本上,统计页面让你看到一堆统计数据,点击一个特定的统计数据会弹出一个模式,并显示与该统计数据相关的所有记录。如果我只是将记录存储在 StatController 上,它工作正常,但我无法使用 ArrayController 进行排序/过滤。 所以它一切都有效,除了当我尝试显示当前列表控制器的内容时,它吓坏了。
感谢您的任何帮助或指导。
当前列表控制器:
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}}
App.CurrentListController
不是一个数组。它是一个对象,一个控制器对象。(顺便说一句,不建议在模板中访问全局名称 [ 即使用任何带有大写字母的内容])
相反,您应该做的是:
App.StatController = Ember.ObjectController.extend({
needs:['currentList'],
currentList: Ember.computed.alias('controllers.currentList.model'),
...
通过这种方式,您可以访问 currentList 控制器(这是一个数组)的基础模型,并将其作为 currentList
提供给您的模板。
{{#each business in currentList}}
...
{{/each}}