2013-02-25 38 views
0

考虑:如何使用SciptDb查询输出到UI标签文本?

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 Object 

此脚本用于在谷歌脚本ScriptDb中,我想输出从查询字符串答案。

回答

0

db.query()results不是含对象的数据,而所述ScriptDbResult实例类似于一个迭代,以hasNext()next()方法来检索数据对象。这在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())); 
相关问题