0
Winjs 약속을 반환하는 데 문제가 있습니다. 코드에 어떤 문제가 있는지 전혀 알지 못합니다. 약속을하고 .done을하거나 내 약속이 아무것도하지 않을 때.약속 배열에 WinJS가 반환되었습니다.
코드 :
function getSth(array) {
return new WinJS.Promise(function() {
var dbPath = Windows.Storage.ApplicationData.current.localFolder.path + '\\_db.sqlite';
var i = 0;
SQLite3JS.openAsync(dbPath)
.then(function (db) {
console.log('DB opened');
return db.eachAsync('SELECT * FROM sthh;', function (row) {
array[i++] = row.sth;
console.log('Get a ' + row.sth);
});
})
.then(function (db) {
console.log('close the db');
db.close();
}).then(function() {
return array;
});
return array;
})
}
그리고 다른 파일에
난 그냥 그런 식으로 뭔가를 할 :var array = [];
var z = getSth(array).then(function() {
console.log("AAA");
for (var i = 0; i < array.length; console.log("#" + array[i]), i++);
});
내가 어떤 제안을 매우 gratefull 될 것입니다.
음 :
난 당신이 더 같은 코드를 작성하려는 생각합니다. 'new WinJS.Promise'의 함수 매개 변수는 전통적으로'c','e' 및'p'라는 세 개의 매개 변수를 취합니다. 결과를 생성하면'c (result)'를 호출합니다. –