【问题标题】:Ember-Table with Fixture Adapter带夹具适配器的 Ember-Table
【发布时间】:2014-04-25 01:12:45
【问题描述】:

我正在尝试使用 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')
});

【问题讨论】:

    标签: ember.js ember-data fixtures ember-table


    【解决方案1】:

    当您使用数组时,对象会变成真实的对象,而不是 Ember.Object。您应该可以使用:

    getCellContent: function (row) {
      return row.get('name');
    }    
    

    正确选择每一行的数据。

    【讨论】:

    • 感谢您的提示!那么,我会使用它而不是 content 属性吗?或者使用它来填充内容属性中的数组?
    • 在这种情况下,row 实际上是为您内容中的每一行调用的。因此,您仍然必须提供内容,但如果您的内容是 ember 对象,则需要在每个对象上使用 get 函数。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-07
    • 1970-01-01
    • 2019-07-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多