MVC in jquery, Multiple data requests from model but single callback needed
Basically the setup is almost the same as [[ One callback for multiple json requests ]], but I think the solution is too hacky and that it should be handle-able in a cleaner way in MVC.
'Tickets' and 'People' are distinct 开发者_开发百科models and there is a getAll method to each. I need to initialize a plugin with data from both getAll methods. They could be ajax requests, but I want to make it oblivious to the plugin caller. I can't think of a way, but I have no experience in MVC, any help guys? Or how should I clean it so that the mvc is cleaner?
I am trying to go after something like this. Thanks!!
$.when(Tickets.getAll(), People.getAll()).then(function(data) {
$.fn.myPlugin = ...
});
Make sure that .getAll
returns a $.Deferred
object so you can abstract away whether loading your models is asynchronous or not.
精彩评论