好的,所以我一直在对 promises 和 futures 进行一些研究......我目前想要实现的是使用自动完成 JQM 通过调用数据库并运行写入输入的术语来填充输入字段. 我已将此 URL 用作参考:here但我似乎无法让它工作......我不断收到此错误:
Uncaught TypeError: Cannot call method 'apply' of undefined at file:///android_asset/www/js/q.js:1230
这是我的代码,因为它有点太大,我在这里创建了一个链接:http: //pastebin.com/Hh3CttMm
对于我的 html ......这是额外的 JS 文件:
var findClients = "SELECT clientname FROM clients WHERE uniqueName LIKE ? AND (clientState = 'NSW' OR clientState = 'MULTIPLE') LIMIT 5";
function listClients(text) {
var clientArray = [];
var queryDB = function queryDB(tx) {
var term = "%" + text + "%";
tx.executeSql(findClients, [term], createList, error2);
}
var createList = function createList (tx, results) {
alert(results.row.length);
for (var i = 0; i < results.rows.length; i++) {
var item = results.rows.item(i);
clientArray.push(item['clientname']);
}
}
return Q.fcall(db.transaction(queryDB, error1)).then(function(){return clientArray});
}
我相信这与页面没有初始化我的 Q.js 文件有关,但我不太确定如何解决这个问题。
编辑:错误在这个函数中,就行throw error
Q.done = done;
function done(promise, fulfilled, rejected, progress) {
var onUnhandledError = function (error) {
// forward to a future turn so that ``when``
// does not catch it and turn it into a rejection.
nextTick(function () {
makeStackTraceLong(error, promise);
if (Q.onerror) {
Q.onerror(error);
} else {
throw error;
}
});
};
// Avoid unnecessary `nextTick`ing via an unnecessary `when`.
var promiseToHandle = fulfilled || rejected || progress ?
when(promise, fulfilled, rejected, progress) :
promise;
if (typeof process === "object" && process && process.domain) {
onUnhandledError = process.domain.bind(onUnhandledError);
}
fail(promiseToHandle, onUnhandledError);
}