0

検討:

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

このスクリプトは Google Script と ScriptDB で使用され、クエリから文字列の回答を出力したいと考えています。

4

1 に答える 1

0

resultsfromはdb.query()データを含むオブジェクトではなく、ScriptDbResultインスタンスは反復子に似ており、hasNext()データnext()オブジェクトを取得するメソッドが含まれています。これはScriptDb ドキュメントで説明されていますが、これらの例をコードに適用する方法は次のとおりです。

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;
}

または、クエリに一致するものが 1 つだけであると確信している場合は、次のようにすることもできます。

app.getElementById('result')
   .setVisible(true)
   .setText(Utilities.jsonStringify(results.next()));
于 2013-07-17T13:41:17.203 に答える