2013-04-27 15 views

回答

2

我認爲,這個解決方案可以是一個好辦法:

executeQuery= function(query){ 
    operating(true); 
    return manager.executeQuery(query).fail(fail); 

    function fail(error){ 
     //You can decide if you want to query locally depending on the type of error 
     //Example: if(error.status===404) ; 
     return executeQueryLocally(query); 
    } 

} 

executeQueryLocally= function(query){ 

    return manager.executeQuery(query).using(FetchStrategy.FromLocalCache).fail(fail); 

    function fail(error){ 
     //You can't get the information, so you can throw an error 
     //Or that you want 

     throw Error('Impossible to get the requested data'); 
    } 
} 

//Example calling this methods 
var getCustomers= function(resultArrayObservable,inlineCountObservable){ 
     var query = new breeze.EntityQuery("Customers").inlineCount(true); 
     return executeQuery(query).then(success); 

     function success(data){ 
      inlineCountObservable(data.inlineCount); 
      resultArrayObservable(standarizeCustomerDtos(mapCustomerDtosToKos(data.results))); 
     } 

}; 

有了這個解決方案,我試圖做簡單的在每一個查詢,以檢查它是否是走錯了,而不是重複代碼的東西。

我希望這可以幫助你。

相關問題