2016-11-26 44 views
2

我已經創建了一個使用react-native的移動應用程序,並且我使用couchbase進行同步。我爲此使用了該模塊。 https://github.com/couchbaselabs/react-native-couchbase-litereact-native couchbase lite按鍵篩選

根據文檔,我可以使用queryView方法從一個鍵過濾。但在我的應用程序中,我只能使用queryView方法來過濾整數值。當我使用queryView方法處理字符串時,它不會過濾來自文檔的值,它只是返回相關類型的所有文檔。按照以下方式我定義了我的觀點。

 views: { 
      person_view: { 
      map: 'function (doc) { if (doc.type === "Person") { emit(doc.name, null);} }' 
      }, 
     } 

以下是過濾方法。

filterDocumentByAttribute(view, key) { 
    return new Promise((resolve, reject) => { 
     let options = { 
     key: key, 
     include_docs: true 
     }; 
     this.database.queryView(DESIGN_DOCUMENT_NAME, view, options) 
     .then((res) => { 
     console.log(res.rows); 
     resolve(res.rows); 
     }) 
     .catch((error) => { 
     console.log(error); 
     reject(error); 
     }); 
    }); 
    } 

當鍵參數是整數時,該方法完美地工作,但是當它是一個字符串時,它只返回所有文檔。

回答