2014-09-02 4 views
0

IBM Worklight의 JSONStore에서 여러 값을 바꿔야합니다. 이렇게하면 첫 번째 값만 저장됩니다. 왜?여러 값 저장 방법 JSONStore

.then(function() {        
    for (var index = 0; index < elencoSpese.length; index++) {           
     var spesa = elencoSpese[index];        
     var spesaReplace = {_id: spesa.id, json: spesa};         
     spesa.id_nota_spesa = idNotaSpesa;        
     spesa.checked = true;        
     WL.JSONStore.get(COLLECTION_NAME_SPESE).replace(spesaReplace); 
    } 
    }) 

답변

1

JSONStore 문서의 배열을 구성하여 replace API에 전달하려고합니다. 예를 들어 :

.then(function() { 

    var replacementsArray = []; 

    for (var index = 0; index < elencoSpese.length; index++) { 
     var spesa = elencoSpese[index]; 
     var spesaReplace = {_id: spesa.id, json: spesa}; 
     spesa.id_nota_spesa = idNotaSpesa; 
     spesa.checked = true; 
     replacementsArray.push(spesaReplace); 
    } 

    return WL.JSONStore.get(COLLECTION_NAME_SPESE).replace(replacementsArray); 

}) 
.then(function (numOfDocsReplaced) { 
    // numOfDocsReplaced should equal elencoSpese.length 
}) 

나는 그 대답이 문서 here에있는 경우라면이의 JSONStore API의 자바 스크립트 구현에서 발생하는 가정합니다. JSONStore의 JavaScript 구현은 코드가 순차적으로 호출 될 것으로 기대합니다. 다음 번에 전화하기 전에 작업이 끝날 때까지 기다리십시오. 대기하지 않고 replace 번을 여러 번 호출하면 직렬 대신 병렬로 API를 호출합니다. 프로덕션 환경 (Android, iOS, WP8 및 W8)에서는 문제가되지 않습니다.

+0

고마워요! 이 방법으로 모든 작품. – Marco