Tag: chaining

jQuery链接和级联然后是什么时候

我目前在我面前有一个非常棒的if-then-else循环,它首先从web服务获得多个cantinas。 然后它会获得所有可用餐点(每个菜单)和所有可用的配菜(每个菜单)。 对于每一餐和两餐,然后检查所有添加剂并聚集它们。 最后, 我有多种菜单,包括餐点,配菜和所有添加剂。 以下流程图显示了该过程: 我想美化代码,并希望利用jQuery的promises – 但我无法弄清楚如何做到这一点,因为我必须在一段时间之后堆叠一个(至少我认为,也许我必须resolve ?) 。 以下是我最好的尝试: //this totally does not work at all, but you get the idea what I want to do Menus.getCantinas() .when(Menus.getMeals(cantinas), Menus.getSides(cantinas)) //when doesn’t exist here, neither does cantinas .then(Menus.getAdditives(meals, sides) //also throws errors as meals and sides does not exist .done(function(cantinas, meals, sides, additives) […]

jQuery ajax调用具有多个依赖关系的链接

我不太了解jQuery的魔术延迟对象。 假设以下代码: function callWebService(uri, filter, callback) { var data = {}; if (filter && filter != ”) data[‘$filter’] = filter; jQuery.ajax({ url: ‘/_api/lists/’ + uri + ‘/items’, data: data, success: callback, dataType: ‘json’ }); } function getInitialData() { callWebService(“InitialData”, “”, function (data) { //do stuff with data }); } function getGreenData() { callWebService(“GreenData”, “filter from […]