1

好吧,你们所有的 jquery 专业人士都在那里。这个问题让我觉得很毛茸茸。我会尽我所能提供尽可能多的信息,以便清楚。

我有一个div的层次结构。它们被设置成三层。每个图层上都有一个刷新按钮。当我单击顶层的刷新按钮时,所有三层的刷新按钮都开始旋转。这正如预期的那样。

目标是当底层的刷新图像停止旋转时(意味着 ajax 调用返回并且该层已更新),我希望父层中的图像也停止旋转。

这是代码中发生的事情:

function refresh(layer){
  switch(layer){
  case 'bottom layer':
      Make ajax call for self and then update page
      Remove class rotate (which makes the image rotate)
  case 'middle layer':
      For each middle layer, call refresh with the middle layer's 'bottom layer' children
  case 'top layer':
      for each top layer, call refresh with 'middle layer' children
  }
}

编辑 我不能告诉父母自己删除班级轮换,因为在对孩子的 ajax 调用完成之前它就被删除了。在孩子完成 ajax 调用之前,我不希望删除父母的课程。

另外,当我说有三层时,我并不完全诚实,因为当单击图像并且该图像在 div 中并且该 div 在中间层标题的 div 中时,实际上正在调用该函数,等等.我可以弄清楚如何导航DOM以到达父母,我只想要一些伪代码和解释如何在所有孩子都完成更新之前不从父母那里删除类轮换。 完成编辑

我当然希望这是有道理的。我不能放实际代码,因为它是专有的而且相当冗长;我们不喜欢代码墙。

当所有底层都完成更新后,如何告诉底层从其父级中删除“旋转”类?

4

3 回答 3

0

I ended up writing a function that takes the class off for me. The function found the parent of the child div and from there had access to all of its children images. In this way, the parent could remove the rotate class from itself and all of its children.

于 2013-08-09T18:10:52.437 回答
0

这可能会帮助您上路。

您可以使用 jQuery.when() 仅在多个 ajax 请求完成时执行某些操作。

$.when($.ajax({
      url: yoururl,
      type: "POST"
     }), $.ajax({
      url: yoururl,
      type: "POST"
     }), $.ajax({
      url: yoururl,
      type: "POST"
     }), $.ajax({
      url: yoururl,
      type: "POST"
     })).done( function() {
        //do your parent remove
     });

http://api.jquery.com/jQuery.when/

于 2013-08-05T20:18:13.490 回答
0

也许我不明白你的问题,但有这个:

var divMiddleLayer = ("divBottomLayer").parent();
var divTopLayer = ("divMiddleLayer").parent();
divMiddleLayer.removeClass("rotate");
divTopLayer.removeClass("rotate");
于 2013-08-05T19:59:27.240 回答