我正在尝试使用 Ember-Data 和 Fixtures 加载 ember 表。我可以看到 table 中生成的行,但是它们是空的。请注意,它确实生成了正确的行数,只是不显示数据。如果我改用数组,一切正常。此外,如果我删除表格并执行 {{#each}},数据也显示得很好。欢迎任何想法!谢谢
这是html:
<div class="table-container">
{{table-component
hasFooter=false
columnsBinding="columns"
contentBinding="content"}}
</div>
这是控制器:
App.CustomersController = Ember.ArrayController.extend({
numRows: 1,
columns: function() {
var nameColumn, typeColumn, phoneColumn, identifierColumn;
nameColumn = Ember.Table.ColumnDefinition.create({
columnWidth: 150,
textAlign: 'text-align-left',
headerCellName: 'Name',
getCellContent: function (row) {
return row.name;
}
});
typeColumn = Ember.Table.ColumnDefinition.create({
columnWidth: 150,
textAlign: 'text-align-left',
headerCellName: 'Type',
getCellContent: function (row) {
return row.type;
}
});
phoneColumn = Ember.Table.ColumnDefinition.create({
columnWidth: 100,
textAlign: 'text-align-left',
headerCellName: 'Phone',
getCellContent: function (row) {
return row.phone;
}
});
identifierColumn = Ember.Table.ColumnDefinition.create({
columnWidth: 150,
textAlign: 'text-align-left',
headerCellName: 'ID',
getCellContent: function (row) {
return row.identifier;
}
});
console.log('in columns func');
console.log(this.get('content'));
return [nameColumn, typeColumn, phoneColumn, identifierColumn];
}.property(),
content: function() {
/*var temp= [
{
id: 1,
name: 'Seller',
type: 'Supermarket',
phone: '1-800-Sell',
identifier: '12345'
},
{
id: 2,
name: 'Sell',
type: 'Supermarket',
phone: '1-800-Sell2',
identifier: '12356'
}];
return temp;*/
return this.store.toArray
}.property('numRows')
});
(请注意,上面还包括了有效的注释数组)
和模型:
App.Customers = DS.Model.extend({
name: DS.attr('string'),
type: DS.attr('string'),
phone: DS.attr('string'),
identifier: DS.attr('string')
});