2015-04-05 64 views
0

我正在使用$ localForage.setItem在離子移動應用程序中本地存儲數據。數據大約爲7MB,並且在使用setItem時App會凍結幾秒鐘。

任何意見如何解決?

回答

0

您可以使用Promises來允許應用程序在獲取數據時繼續運行。

localforage.getItem("sellerName").then(function(sellerName) { 
     // .... Any code that DEPENDS ON THIS DATA goes here. 
     // THIS code will have a pause prefacing it, but code 
     // outside of this funtion will continue to process. 
}); 

希望這可以幫助你!如果您的數據取決於正在檢索的數據,則可能需要儘快檢索(如緩存)或暫時在屏幕上放置加載程序映像。祝你好運!

附錄:你可以試試這個,我已經使用了獲取「大數據」,並獲取多個大數據結果...

var getLogs = $.ajax({ type: 'GET', url: 'testget.php?more=1' }); 
$('#results').html('Loading...'); 
$.when(getLogs).then(function(getLogs) { 
    $('#results').html(getLogs); 
}, handleError); 
function handleError(xhr, status, error) { 
    console.log("There was an Error: " + error.toString()); 
} 

這應該處理您的問題。^5

+0

問題是關於設置項目,即使使用承諾回調我也有類似的問題。 – DazChong 2016-03-16 08:46:08