2013-02-25 1 views
0

고려 :SciptDb 쿼리 출력을 UI 레이블 Text에 어떻게 사용할 수 있습니까?

function submit(e) { 


var db = ScriptDb.getMyDb(); 
    // Clear the values from the text boxes so that new values can be entered 
    var app = UiApp.getActiveApplication(); 
    app.getElementById('description').setValue(''); 
    app.getElementById('model').setValue(''); 
    app.getElementById('productCode').setValue(''); 
    // Make the status line visible and tell the user the possible actions 
    var db = ScriptDb.getMyDb(); 
    var results = db.query({BarCode:'productCode'}); 

    app.getElementById('result').setVisible(true).setText(Utilities.jsonStringify(results)); 
    return app; 
}​ 

그것은 단지 출력 후가 아니라 그 결과,이 스크립트는 ScriptDb에와 구글 스크립트에 사용되며, I 출력에 쿼리 문자열 대답을 원하는

ScriptDb Object 

. ScriptDbResult 인스턴스 데이터 객체를 검색 및 hasNext()next() 방법으로, 반복자 유사 오히려

답변

0

db.query()에서 results는 데이터 오브젝트가 포함되지 않는다. 이것은 ScriptDb documentation 설명하지만, 여기에 당신이 당신의 코드에 그 예를 적용 할 방법있다 : 당신이 당신의 쿼리에서 하나의 일치있을 것이라는 점을 신뢰하는 경우,

function submit(e) { 
    // Clear the values from the text boxes so that new values can be entered 
    var app = UiApp.getActiveApplication(); 
    app.getElementById('description').setValue(''); 
    app.getElementById('model').setValue(''); 
    app.getElementById('productCode').setValue(''); 

    // Make the status line visible and tell the user the possible actions 
    var db = ScriptDb.getMyDb(); 
    var results = db.query({BarCode:'productCode'}); 
    var output = ""; 
    while (results.hasNext()) { 
    var item = results.next() 
    output += item.toJson(); 
    } 

    app.getElementById('result').setVisible(true).setText(output); 
    return app; 
} 

또는 당신이 할 수 있습니다 :

app.getElementById('result') 
    .setVisible(true) 
    .setText(Utilities.jsonStringify(results.next())); 
관련 문제