jQuery CouchDB-筛选视图的键 [英] jQuery CouchDB - filter keys for view
问题描述
我正在使用沙发床附带的JavaScript库来查询数据库。
I am using the javascript library which comes bundled with couchdb to query the database.
在旁边的注释中,它很好地概述了其提供的功能,并提供了许多很好的示例。
可以通过指定要返回的键值从视图中过滤结果。使用查询字符串即可轻松完成此操作(文档),但是如何使用javascript API做到这一点?
It is possible to filter the results from a view by specifying the key values to return. This is easily done with a query string (documentation) but how do I do it with the javascript API?
这就是我使用查询字符串的方式(请注意,键值对的JSON部分需要进行HTML编码):
This is how I am doing it with a query string (please note that the JSON portion of the key-value-pair would need to be HTML encoded):
http://localhost:5984/MyDocuments/_design/MyDesign/_view/MyView?key=["Michael","2011-08-01"]
这是我的javascript,其中未应用过滤过程的查询字符串部分。
And this is my javascript without the query string portion of the filtering process applied.
$.couch.db("MyDocuments").view("MyDesign/MyView", {
success: function(data) {
console.log(data);
},
error: function(status) {
console.log(status);
},
reduce: false
});
推荐答案
我在写问题时实际上已经想到了这一点。相当简单,但在线上没有很多示例,因此需要利用这个机会来提供示例。
I actually figured this one out while writing the question. It was reasonably easy but there are not a lot of examples online so therefore feel the need to take this opportunity to provide an example.
$.couch.db("MyDocuments").view("MyDesign/MyView", {
success: function(data) {
console.log(data);
},
error: function(status) {
console.log(status);
},
key: ['Michael','2011-08-02'],
reduce: false
});
关键部分是您要查找的内容:)
The "key" section is what you are looking for :)
这篇关于jQuery CouchDB-筛选视图的键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!