I have a function to get some data, and the function should return a promise. In the function, I have to made 2 requests - one after another. I ended up with a nested deferrer call where the last call resolves
on the deferrer the function will return. I'm new to this deferred stuff and wonder if this is the right solution.
function getData(func) {
var model = new Model();
var collection = new Collection();
var dfd = new jQuery.Deferred();
collection.fetch().then(function () {
model.fetch().then(function () {
dfd.resolve(collection);
});
});
return dfd.then(function (collection) {
return getViews(func(collection), model);
});
}