어떻게 웹 sql 의 비동기 문 제 를 해결 합 니까?
원문:http://stackoverflow.com/questions/4052479/html5-database-api-synchronous-request
To get an object implementing
DatabaseSync
you have to call openDatabaseSync(...)
instead of openDatabase(...)
. I don't know about the iPhone, or what the oDB
object you have is, but according to spec you only get the openDatabaseSync
method in a WebWorker and not in the normal web browser window
. Certainly XMLHttpRequest
has demonstrated that potentially-length synchronous operations in the UI thread are not a good idea. 2. 외국인 의 또 다른 방안 을 살 펴 보 았 다.http://stackoverflow.com/questions/3903155/synchronous-query-to-web-sql-database
사실 리 셋 함수 에 직접 쓸 수 있 음 을 발견 하면 여러 함수 로 나 눌 필요 가 없습니다. 그러면 비동기 문 제 를 해결 할 수 있 습 니 다. 다음 과 같 습 니 다. (모든 코드 논 리 는 리 셋 함수 에서 이 루어 집 니 다)
functiongetFolder(id, callback) {
vardata = [];
ldb.transaction(function(tx) {
tx.executeSql('SELECT * FROM folders where id=?',
[id],
function(tx, results) {
if(results.rows && results.rows.length) {
for(i = 0; i < results.rows.length; i++) {
data.push(results.rows.item(i));
}
}
if( typeof(callback) == 'function') callback(data);
},
function(tx, error) {
console.log(error);
});
});
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
위 챗 애플 릿 가 져 오기 시스템 시간, 시간 스탬프, 시간 스탬프 가감텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.