couchbase-如何在angular中设置queryView选项?
函数couchbase.getDatabase().queryView()始终返回所有行。我找不到正确设置选项的方法couchbase-如何在angular中设置queryView选项?,angular,typescript,ionic3,couchbase-lite,Angular,Typescript,Ionic3,Couchbase Lite,函数couchbase.getDatabase().queryView()始终返回所有行。我找不到正确设置选项的方法 let options = { key: ["First", "1"], include_docs: true } this.couchbase.getDatabase().queryView("_design/dispatch", "orders", options) .then(result => { console.log(result)}); }
let options = {
key: ["First", "1"],
include_docs: true
}
this.couchbase.getDatabase().queryView("_design/dispatch", "orders", options)
.then(result => {
console.log(result)});
}
我在couchbase.ts中的观点:
let views = {
orders: {
map: function(doc) {
if (doc.type == "orders" && doc.district) {
emit([doc.district, doc.done], {
name: doc.name,
rev: doc._rev
});
}
}.toString()
}
};
从map函数可以看出,您正在为该键发射一个数组。您已将键指定为单个键的数组,而不是与索引匹配的数组。所以你需要
let options = {
key: [["First", "1"]],
include_docs: true
}
queryView
只是使用$http
对象对调用进行简单包装。以下是相关的代码片段:
queryView: function(designDocumentName, viewName, options) {
return this.makeRequest("GET", this.databaseUrl + this.databaseName + "/" + designDocumentName + "/_view/" + viewName, options);
}
因此,您可以看到它正在使用对设计文档REST端点的GET调用
如果调试该问题时遇到问题,您可能希望尝试对同步网关API使用curl命令。这更容易做到(并且可以查看日志输出等),它非常类似于Couchbase Lite API。看看这些文件