.minを使うときは.mapも入れる
underscoreとjqueryに依存
JQueryのDefferdオブジェクトを使う
$.when(function(){})
.then(function(whenの中の関数の戻り値){
}).done(function(thenの中の関数の戻り値){});
非同期リストクエリ
var FileListCollection = Backbone.Collection.extend({
model : FileListModel, url : 'XXX', deferredFetch : function(event, props) { var deferredObj = $.Deferred(); var result = this; var fetchedModels = this.fetch({ success : function() { deferredObj.resolve(result); }, error : function() { deferredObj.reject(result); } }); return deferredObj.promise(); }
});
var fileListCollection = new FileListCollection();
fileListCollection.deferredFetch()
.then(function(val) {
console.log('call then'); console.dir(val); return val;
})
.done(function(val) {
console.log('call done'); console.dir(val);
});