在 CouchApp 查询中调用多个视图 [英] Calling multiple views in CouchApp query

查看:25
本文介绍了在 CouchApp 查询中调用多个视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要根据在表单中输入的几个条件来搜索 CouchDB.名称、标签数组等.然后我需要各种视图来索引这些字段.最终,所有结果都将在 data.js 中进行整理并提供给 mustache.html.假设有 3 个视图 - docsByName、docsByTags、docsById.

I need to search the CouchDB based on several criteria entered in a form. Name, an array of Tags and so on. I would then need various views to index on these fields. Ultimately, all the results will be collated in data.js and provided to mustache.html. Say there are 3 views - docsByName, docsByTags, docsById.

我不知道的是,如何在 query.js 中查询所有这些视图.这能做到吗?如何做到?

What I don't know is, how to query all these views in query.js. Can this be done and how ?

或者该方法应该是编写一个视图,以某种方式为每次搜索进行多次发射?

Or should the approach be of that to write one view that makes multiple emits for each search somehow ?

谢谢.

推荐答案

从你说的我假设你正在使用 Evently,所以我会引用Evently Primer:

From what you say I assume you are using Evently, so I will quote from Evently primer:

async 函数是主星,在本例中它发出 Ajax 请求(但它可以做任何它想做的事情).另一个需要注意的重要事情是异步函数的第一个参数是一个回调,当你完成异步操作时,你用它告诉 Evently.[...] 传递给回调函数的任何内容都会成为传递给数据函数的第一项.

The async function is the main star, which in this case makes an Ajax request (but it can do anything it wants). Another important thing to note is that the first argument to the async function is a callback which you use to tell Evently when you are done with your asynchronous action. [...] Whatever you pass to the callback function then becomes the first item passed to the data function.

简而言之:将您的 Ajax 请求放在 async.js 中.

In short: put your Ajax requests in async.js.

附带说明:Evently 只是编写 couchapp 的可能选择之一,是否维护尚不清楚.但是它可以工作,并且很容易重新排列代码以不使用它.

As a side note: Evently is only one of the possible choices to write a couchapp and it is not clear if it is maintained. However it works and it is easy to rearrange the code to not use it.

这里是一个示例异步函数(从旧程序中剪切和粘贴):

here is a sample async function (cut&paste from an old program):

function(cb, e) {
  var app = $$(this).app
    ;
  app.db.openDoc('SOMEDOCID', {
    error: function(code, error, reason) {
      alert("Error("+code+" "+error+"): "+reason);
    }
  , success: function(doc) {
      app.view('SOMEVIEWNAME', {
        include_docs: true
      , error: function(code, error, reason) {
          alert("Error("+code+" "+error+"): "+reason);
        }
      , success: function(resp) {
          resp.doc = doc;
          cb(resp);
        }
      });
    }
  });
}

这篇关于在 CouchApp 查询中调用多个视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆