开发者

MVC in jquery, Multiple data requests from model but single callback needed

开发者 https://www.devze.com 2023-03-06 01:27 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消