将 Knockout.js 与 CouchDB 结合使用 - 更改时更新
只是想知道订阅我的 CouchDB 数据存储的最佳方式,这样如果沙发中的文档更新,KO 视图也会更新(自动)。这有可能吗?
下面是我到目前为止所得到的,它只是从 user_info 文档中获取用户名。
$.getJSON('http://localhost/couchdb/user_info', function(data) {
var viewModel = ko.mapping.fromJS(data);
ko.applyBindings(viewModel);
});
任何帮助将不胜感激!
Just wondering about the best way to subscribe to my CouchDB data store, so that if a document in couch is updated, the KO view will also update (automagically). Is this something that's even possible?
Below is what I have so far, which simply get the user name from the user_info document.
$.getJSON('http://localhost/couchdb/user_info', function(data) {
var viewModel = ko.mapping.fromJS(data);
ko.applyBindings(viewModel);
});
Any help would be greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
CouchDB 支持文档更改时的通知:更改源。
您可以使用
?since=X
参数轮询更改 Feed,以仅接收自 X 以来的更新。您还可以通过添加
&feed=longpoll
来“长轮询”Feed >。如果尚未发生任何更改,CouchDB 将收到您的查询,但不会回答,直到最终发生更改。或者,您可以通过添加
&feed=continuous
来获得完整的 COMET 样式提要。这与 longpoll 类似,但 CouchDB 永远不会关闭连接。每次发生更改时,它都会向您发送 JSON,然后继续等待。最后,当数据库中发生任何变化时,您都会收到通知,或者您可以指定要在服务器上运行的 Javascript 过滤器 (
&filter=designdoc/filtername
)。仅当过滤器批准时您才会收到通知。CouchDB supports notifications when documents change: the changes feed.
You can poll the changes feed, with a
?since=X
parameter to receive only updates since X.You can also "long poll" the feed by adding
&feed=longpoll
. If there are no changes yet, CouchDB will receive your query but not answer until finally a change comes on.Or, you can have a full COMET-style feed by instead adding
&feed=continuous
. That is similar to longpoll, however CouchDB will never close the connection. Every time a change happens, it will send you the JSON and then continue waiting.Finally, you can be notified when anything changes in the database, or you can specify a Javascript filter to run on the server (
&filter=designdoc/filtername
). You will only receive notifications if the filter approves.你看过http://hood.ie/吗,效果很好。我还在 couchdb 中将 hoodie 作为 os_daemons 服务运行。
很好。
Have you looked at http://hood.ie/ it woks well. I'm also running hoodie as an os_daemons service from within my couchdb.
It's nice.