2016-09-16 2 views
0

나는 couchbase 라이트에 초보자이며 당신의 도움이 필요합니다. 오프라인에서 데이터 및 액세스를 저장하고 phonegap 앱에 표시하려고합니다. 그래서 저는 couchbase lite를 선택합니다. 일부 step.There을 할phonegap에서 couchbase 라이트에서 전체 문서 검색

사용 예제 코드는

  • 는 카우치베이스 주식회사 라이트 프레임 워크를 추가합니다.
  • phonegap 앱에서 실행하십시오.
  • 로컬 couchbase 라이트 URL을 가져옵니다.
  • 데이터베이스를 만듭니다.
  • 문서를 삽입, 업데이트 및 삭제하기위한 데이터베이스 연결.

    그러나 내 문제는 데이터베이스에서 전체 문서를 검색합니다. 동시에지도 검색 방법을 통해 문서를 검색합니다. 그러나 나는 이해할 수 없다.

    샘플 폰갭의 응용 프로그램 : Here the link 내가 작업 코드를 첨부 아래

    , 당신은 JS의 VAR로 전달 된 문서를 얻을 IOS 플랫폼

    var coax = require("coax"); 
    console.log(coax); 
    var appDbName = "couchdb"; 
    document.addEventListener('deviceready', onDeviceReady, false); 
    
    // deviceready Event Handler 
    // 
    // The scope of 'this' is the event. In order to call the 'receivedEvent' 
    // function, we must explicitly call 'app.receivedEvent(...);' 
    
    function onDeviceReady() { 
    receivedEvent('deviceready'); 
    setupConfig(function(err){ 
          if (err) { 
          alert(err) 
          return console.log("err "+JSON.stringify(err)) 
          } 
          }); 
    
    } 
    
    function logMessage(message) { 
    var p = document.createElement("p"); 
    p.innerHTML = message; 
    document.body.getElementsByClassName('app')[0].appendChild(p); 
    console.log(message); 
    } 
    
    // Update DOM on a Received Event 
    
    function receivedEvent(id) { 
    var parentElement = document.getElementById(id); 
    var listeningElement = parentElement.querySelector('.listening'); 
    var receivedElement = parentElement.querySelector('.received'); 
    
    listeningElement.setAttribute('style', 'display:none;'); 
    receivedElement.setAttribute('style', 'display:block;'); 
    
    console.log('Received Event: ' + id); 
    } 
    
    
    
    function setupConfig(done) { 
    // get CBL url 
    if (!window.cblite) { 
        return done('Couchbase Lite not installed') 
    } 
    cblite.getURL(function(err, url) { 
           console.log("getURL: " + JSON.stringify([err, url])); 
    
           window.server = coax(url); 
    
           var db = coax([url, appDbName]); 
    
           setupDb(db, function(err, info){ 
             console.log("getDB"+db); 
    
             if (err) { 
             return alert(JSON.stringify("GetDB:"+ err)); 
             } 
    
             db.get("_local/user", function(err, doc) { 
             if (err) { 
    
              if(err.status == 404) { 
    
    
              var docV = { "key" : "value" }; 
              db.put("_local/user", docV, function(err, ok) { 
              //HERE I AM INSERT THE DATA 
              return alert(JSON.stringify("Success:" + ok)); 
              }); 
    
    
              } 
              else { 
              return alert(JSON.stringify(err)); 
              } 
    
             } 
             else { 
              console.log("Document : "+doc._id); 
              // HERE I AM UPDATE AND DELETE THE DATA 
              doc._deleted =true; 
              db.put("_local/user", doc, function(error, ok) { 
    
              }); 
    
    
              } 
    
             }); 
    
    
             }); 
    
           }); 
    
    } 
    
        function setupDb(db, cb) { 
         db.get(function(err, res, body){ 
         console.log(JSON.stringify(["before create db put", err, res, body])) 
         db.put(function(err, res, body){ 
           db.get(cb); 
           }) 
         }) 
    } 
    

답변

0

에서 테스트. 여기에 (당신이 링크 된 샘플 응용 프로그램에서)이 표시됩니다 작은 조각이다 : 문서에서

function toggleChecked(id) { 
    log("toggle", id) 
    config.db.get(id, function(err, doc){ 
     doc.checked = !doc.checked 
     doc.updated_at = new Date() 
     config.db.put(id, doc, function(){}) 
    }) 
} 

등록이 가능하고 직접 업데이트됩니다.

관련 문제