Backbone.Marionette の要求応答フレームワークを使用して、コレクション内のデータを取得し、それを要求する要求オブジェクトに応答しますが、明らかに、コレクションが取り込まれるのを待ちません。そして、ここに私のコードがあります:
これは、データを要求している場所です。
// Module: Timeline, ListController
var employees = App.request('employee:timeline');
ここで、ハンドラーを設定します。
// Entities Module
App.reqres.setHandler('employee:timeline', function() {
return API.getEmployeesForTimeline();
});
ここに私のAPIの機能があります:
getEmployeesForTimeline: function() {
var employees = new Entities.EmployeeCollection();
employees.fetch({
success: function(employees) {
returnEmployees(employees);
}
});
function returnEmployees(employees) {
// doing some things with employees collection
return leaves;
}
}