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)'。 –