2013-10-28 16 views
0

我正在創建一個應用程序,我想從數據庫local.I獲取數據,我有3個表。我想要什麼時,我從第一張表中獲取數據說從僱員的詳細信息我檢查一些條件,如果員工是超級用戶,那麼它會從第二表項目details.So我想要的是當員工是超級用戶它應該開始執行數據從第二個表中取出,然後進一步移動。但是,當它發生超級用戶條件並且一旦它發現tx.executeSql函數使得線程並繼續從第一個表進一步執行並且在完成它開始從項目細節執行數據之後發生了什麼。 任何人都可以幫助使這個執行工作在我想要的流程中。如何在手機間隙中同步執行另一個Tx.executeSql函數中的tx.executeSql函數android

function getusersdetails() 
{ 
     db.transaction(function(tx){ 
      tx.executeSql('select * from users',[],function(tx,results){ 
       var dataset = results.rows.length; 
       if(dataset>0) 
       { 
        for(var i=0;i<dataset;i++) 
        { 
         if(results.rows.item(i).employ_type =='SU') 
         { 
          tx.executeSql('Select * from accessRites where user_Id = results.rows.item(i).user_id',[],function(tx,result){ 
           //some execution here; 
          }); 
         } 
         else if(results.rows.item(i).employ_type =='Manager') 
          { 
           tx.executeSql('Select * from usergroups where user_Id = results.rows.item(i).user_id',[],function(tx,results){ 
            // some execution here; 
           }); 
          } 
         else 
         { 
          //some execution here; 
         } 
         //here some usere execution ; 
        } 
       } 
      }); 
     }); 

在當用戶類型是蘇它然後代替儘快execting第二第二功能,因爲它檢測到tx.executeSql函數它繼續所述第一查詢exeution然後將上面的代碼運行在tx.execute SU條件我想要的是,如果用戶類型是Su,那麼它應該完成其中的tx.excute函數,然後繼續進一步執行,因爲最後需要數據。 任何想法表示讚賞。 在此先感謝。

+0

球員我只想問如何在條件爲真的情況下同步執行另一個tx.executeSql中的tx.executeSql函數,然後繼續執行.. –

+0

當你保守祕密時,我們該如何幫助你的代碼? –

+0

@CL我已經放置了代碼,請將其從保留中移除...... –

回答

0

executeSql回調總是異步執行的。

您應該編寫代碼,以便每個「某些執行此處」代碼獨立於任何其他代碼。

或者,你可以得到所有你想要的數據連接,讓你有一個結果集:

tx.executeSql('SELECT * FROM users' + 
       ' LEFT JOIN accesRites USING (user_Id)' + 
       ' LEFT JOIN usergroups USING (user_Id)', 
       [], function(tx, result){ 
    for (var i = 0; i < results.rows.length; i++) { 
     if (results.rows.item(i).employ_type =='SU') { 
      ... 
     } else if (results.rows.item(i).employ_type =='Manager') { 
      ... 
     } else { 
      ... 
     } 
    } 
}); 

注:如果有多個匹配accessRights/usergroups記錄一個users記錄,您將得到多個記錄,結果中包含重複的users數據。

+0

我已經以相同的方式返回代碼,但如果我想訪問數據從另一個表中,如果條件爲真,然後在訪問數據後,它應該繼續執行。 –

+0

異步回調無法繼續。 –

+0

所以你可以告訴我任何替代做這個... –

相關問題