findAll()的单一模型?

时间:2013-03-25 19:41:35

标签: ember.js

我想使用我的模板&查看以编辑单个记录。服务器返回可能已填充或未填充的阵列。 Controller是ObjectController,我目前通过findAll(1)填充它。如何使用findAll()并返回返回数组中的第一项或空对象?

由于

1 个答案:

答案 0 :(得分:1)

我要做的是拥有一个ArrayController来保存findAll调用的结果,然后将其绑定到:{/ p>

App.RecordsController = Ember.ArrayController.extend();

App.RecordController = Ember.ObjectController.extend({
    needs: 'records',
    contentBinding: 'controllers.records.firstObject'
});

在您的路线中,您可以:

setupController: function () {
    this.controllerFor('records').set('content', Blah.findAll());
}
相关问题