我有复制在CouchDB中工作,并且想要在更改推送到目标数据库时更新我的UI。我读过关于_changes数据库API的信息,并在jquery.couch.js中找到了couch.app.db.changes()函数。但是我无法弄清楚如何使用该函数。我假设我需要设置监听器,但是我对Javascript的知识还不是它所需要的。CouchDB _changes通知-jquery.couch.js couch.app.db.changes()用法
不幸的是,文档http://www.couch.io/page/library-jquery-couch-js-database甚至没有列出changes()函数。
有人可以帮助我在这里,也让我知道什么选项帕拉姆是。
这里是有问题的函数的代码:关于使用jQuery的Ajax的feateures
changes: function(since, options) {
options = options || {};
// set up the promise object within a closure for this handler
var timeout = 100, db = this, active = true,
listeners = [],
promise = {
onChange : function(fun) {
listeners.push(fun);
},
stop : function() {
active = false;
}
};
// call each listener when there is a change
function triggerListeners(resp) {
$.each(listeners, function() {
this(resp);
});
};
// when there is a change, call any listeners, then check for another change
options.success = function(resp) {
timeout = 100;
if (active) {
since = resp.last_seq;
triggerListeners(resp);
getChangesSince();
};
};
options.error = function() {
if (active) {
setTimeout(getChangesSince, timeout);
timeout = timeout * 2;
}
};
// actually make the changes request
function getChangesSince() {
var opts = $.extend({heartbeat : 10 * 1000}, options, {
feed : "longpoll",
since : since
});
ajax(
{url: db.uri + "_changes"+encodeOptions(opts)},
options,
"Error connecting to "+db.uri+"/_changes."
);
}
// start the first request
if (since) {
getChangesSince();
} else {
db.info({
success : function(info) {
since = info.update_seq;
getChangesSince();
}
});
}
return promise;
},
感谢koleto,这工作,以及我一直在做的其他工作,我能够解决如何使用couch.app.db.changes()函数。对不起,迟到的回应,但我不知道有另一个答案张贴。 – nevf 2010-12-04 03:05:06