2014-01-17 2 views
0

새 문서를 추가하기 전에 모든 문서를 컬렉션 및 메모리에서 지우려고했습니다. 나는 다음과 같은 방법 IBM Worklight JSONStore | 컬렉션에서 문서를 제거하고 메모리에서 지우십시오.

 WL.JSONStore.get("users").findAll().then(function (arrayResults){ 
      var options={push:true}; 
     if(arrayResults.length>0){ 
      for(var i=1;i<=arrayResults.length;i++){ 
      WL.JSONStore.get("users").remove(i,options); 
      } 
     } 
      }); 

2.

  WL.JSONStore.get("users").findAll().then(function (arrayResults){ 
      var options={}; 
     if(arrayResults.length>0){ 
      for(var i=1;i<=arrayResults.length;i++){ 
      WL.JSONStore.get("users").erase(i,options); 
      } 
     } 
      }); 

그러나 성공을하지 않았다

1.

하여 시도했다. 그것으로 모든 문서를 보여주는 그것의 findAll

답변

4

당신은 컬렉션의 모든 워드 프로세서를 제거하기 위해 API 호출을 사용할 수 있습니다. 다시 사용하려면 컬렉션을 다시 초기화해야합니다.

또한,이 예를 다음 시도 :

function wlCommonInit() { 

    WL.JSONStore.init({ 
    users: { 
     name: 'string' 
    } 
    }) 

    .then(function() { 
    return WL.JSONStore.get('users').add([{name: 'hello'}, {name: 'world'}]); 
    }) 

    .then(function() { 
    return WL.JSONStore.get('users').findAll(); 
    }) 

    .then(function (res){ 

    alert('Before - Docs inside:' + JSON.stringify(res)); 

    var ids = res.map(function(current){ return current._id }) 

    var promises = []; 

    while (ids.length) { 
     promises.push(WL.JSONStore.get('users').remove(ids.pop())); 
    } 

    return WLJQ.when.apply(null, promises); 
    }) 

    .then(function() { 
    return WL.JSONStore.get('users').findAll(); 
    }) 

    .then(function (res) { 
    alert('After - Docs inside:' + JSON.stringify(res)); 
    }) 

    .fail(function (err) { 
    alert('Failed:' + err.toString()); 
    }); 
} 
+0

이봐! 덕분에 Cnandreu ... 나는 내 문제를 해결하기 위해 removeCollection API를 사용했다. –

관련 문제