2011-05-12 2 views
0

sqlite 데이터베이스에서 고유 ID 배열을 얻는 자바 함수를 작성하려고합니다 & 다음에 다른 함수에서 사용되도록 전달합니다. 다른 SQL 쿼리에서 사용할 수 있으며 동적으로 생성 된 목록의 일부이기도합니다.한 함수에서 다른 함수로 sqlite 쿼리에 사용하기 위해 Javascript 변수 전달

ids 행 [ 'id']을 배열 변수 window.symp [i]에 전달할 수있었습니다. 하지만 두 번째 함수에서 올바르게 액세스 할 수없는 두 번째 함수를 제대로 ID를 동적 HTML을 만들 수 있지만 sqlite 쿼리에 전달 된 변수를 실패하거나 만든 모든 목록 항목에서 동일한 값입니다. 어떤 도움을 크게 감상 할 수있다 - 나는 아래의 두 기능 포함했다 :

주요 문제는 당신 대신 당신이 무엇을의

"SELECT sid, symptom FROM slinks WHERE id LIKE ('" + window.symp.join(',') + "')" 

을 필요로한다는 것입니다 :

function showContent() { 
    db.transaction(function (tx) { 
     tx.executeSql("SELECT id, notes FROM webkit WHERE notes LIKE 'A%'", [], function (tx, result) { 
      var notesanode = document.getElementById('notesa'); 
      notesanode.innerHTML = ""; 

      for (var i = 0; i < result.rows.length; ++i) { 
       var row = result.rows.item(i); 
       window.symp[i] = i; 
       window.symp[i] = row['id']; 
       var noteadiv = document.createElement('div'); 
       noteadiv.innerHTML = '<li class=\"arrow\"><a id=\"0\" onClick=\"showSymptoms()\" href=\"#symptoms\">' + row['notes'] + " " + row['id'] + '</a></li>'; 
       notesanode.appendChild(noteadiv); 

      } 

     }, function (tx, error) { 
      alert('Failed to retrieve notes from database - ' + error.message); 
      return; 
     }); 
    }); 
} 

function showSymptoms() { 
    db.transaction(function (tx) { 
     tx.executeSql("SELECT sid, symptom FROM slinks WHERE id LIKE ('" + symp + "')", [], function (tx, result) { 
      var symptomnode = document.getElementById('symptomid'); 
      symptomnode.innerHTML = ""; 

      for (var i = 0; i < result.rows.length; ++i) { 
       var row = result.rows.item(i); 
       var symptomdiv = document.createElement('div'); 
       symptomdiv.innerHTML = '<p><label> <input type=checkbox>' + row['symptom'] + '</label></p>'; 
       symptomnode.appendChild(symptomdiv); 
      } 

     }, function (tx, error) { 
      alert('Failed to retrieve notes from database - ' + error.message); 
      return; 
     }); 
    }); 
} 

답변

0

내가 두 가지 일을 참조 그곳에.

두 번째 문제

window.symp[i] = i; 
window.symp[i] = row['id']; 

방금 ​​가서 그것이 바로 뒤에 선으로 덮어 도착하기 때문에 window.symp[i] = i;을 제거 할 수있다이다.

+0

select 문에'window.symp.join (',')'을 사용하면 어떻게됩니까? –

+0

죄송합니다.하지만 작동하지 않습니다. 변수를 테스트 할 때 변수 window.symp가 올바른 모든 ID를 보유하고 있기 때문에 아무것도 동적으로 만들지 못했습니다. 그러나 어떤 이유로 든 두 번째 함수 select 문에서 개별적으로 액세스 할 수 없습니다. 제안한대로 나는 window.symp [i] = i; 그건 괜찮아. 더 이상의 입력은 크게 감사하겠습니다. – Derek

+0

select 문에 window.symp.join (',')을 추가하면 결과가없는 페이지가로드되고 symp 변수를 테스트하면 이전과 동일한 배열이 유지됩니다. – Derek

관련 문제