2013-04-20 22 views
0

我有一個三級jstree.After作出所有選擇後,我調用displayCount()方法來顯示基於選擇的正確的搜索結果計數。現在,當我取消選中一個選擇時,它將徹底檢查所有節點以保持適當的選定結構,然後調用displayCount()方法。但問題是,在取消選中節點之前,它已經調用了displayCount()方法。我得到錯誤的計數。方法調用的順序如下: -如何維護順序的jQuery方法調用?

 UnchekSelectedNodes(){ 
      // nodes are getting unchecked depends on parent-child relation. 
      // purely DOM structure update operation. 
     } 

     displayCount(){ 
     // ajax call to show proper count based on selected nodes/checkboxes 
     } 

     checkForEmptyDiv(){ 
     // if it becomes no selected hide the div. 
     } 

問題is..always displayCOunt()UnchekSelectedNodes完成()operation.I試圖與法chainng取決於flag.It不起作用之前被調用。

任何解決方案?

+0

http://api.jquery.com/jQuery.ajax看到'async' – user2264587 2013-04-20 15:26:15

回答

0

你可以簡單地做一個setTimeout的...

當I'm懶惰,東西順序錯誤發生,我只是添加的setTimeout與1超時,那麼所有其他呼叫會被稱爲我的之後超時。

UnchekSelectedNodes(){ 
      // nodes are getting unchecked depends on parent-child relation. 
      // purely DOM structure update operation. 
     } 

     displayCount(){ 
     setTimeout(function() { 
      //just do what ever you want. 
     }, 1); 
     } 

     checkForEmptyDiv(){ 
     // if it becomes no selected hide the div. 
     } 
+0

盧克感謝您的快速reply..can請您簡單snippet..it闡述將是對我很大的幫助。 – 2013-04-20 15:25:14

+0

請參閱更新。如果我正確理解你的問題,這將幫助你。 – Luke 2013-04-20 15:39:56