Ember-Model:在Ember-CLI中定义模型类的正确方法?

时间:2014-07-30 00:52:19

标签: ember.js ember-cli ember-model

我的具体错误信息是:

Error while processing route: debtor.index Ember.Adapter must implement find

以下是我定义的模型:

var attr = Ember.attr, hasMany = Ember.hasMany;

export default Ember.Model.extend({
    debtor_id:                  attr(),
    debtor_full_name:           attr(),
    debtor_next_contact_date:   attr(),
    debtor_street1:             attr(),
    debtor_street2:             attr(),
    debtor_city:                attr(),
    debtor_state:               attr(),
    debtor_postal_code:         attr(),
    debtor_country_name:        attr(),
    debtor_tax_id:              attr(),
    debtor_date_of_birth:       attr(),
    debtor_email:               attr(),
    debtor_balance:             attr()
});

this.adapter = Ember.RESTAdapter.create();
this.url = 'api/rest/debtor'
this.rootKey = 'data';
this.collectionKey = 'debtors';
this.primaryKey = 'debtor_id';

这是债务人的路线:

import Debtor from '../models/debtor';
export default Ember.Route.extend({
    model: function(params) {
        return Debtor.find(params.debtor_id);
    }
});

我的问题:正在使用this正确的方法在模型中定义这些属性(考虑Ember-CLI语法)?我还缺少其他可能导致此错误的内容吗?

1 个答案:

答案 0 :(得分:1)

命名并使用该变量感觉更为惯用。

var DebtorModel = Ember.Model.extend({
    debtor_id:                  attr(),
    debtor_full_name:           attr(),
    debtor_next_contact_date:   attr(),
    debtor_street1:             attr(),
    debtor_street2:             attr(),
    debtor_city:                attr(),
    debtor_state:               attr(),
    debtor_postal_code:         attr(),
    debtor_country_name:        attr(),
    debtor_tax_id:              attr(),
    debtor_date_of_birth:       attr(),
    debtor_email:               attr(),
    debtor_balance:             attr()
});

DebtorModel.adapter = Ember.RESTAdapter.create();
DebtorModel.url = 'api/rest/debtor'
DebtorModel.rootKey = 'data';
DebtorModel.collectionKey = 'debtors';
DebtorModel.primaryKey = 'debtor_id';

export default DebtorModel;