0

テキストボックスがフォーカスを得たときにテキストを強調表示する、テキストボックス用の汎用サーバーハンドラーを作成しようとしています:

function onFocusHighlight(e) {
  var app = UiApp.getActiveApplication();
  var widget = app.getElementById(e.parameter.source);
  var widgetValue = e.parameter.widgetName; // how can I get widgetName from source???  
  widget.setSelectionRange(0, widgetValue.length);  
  return app;
}

e.parameter.source から widgetValue を決定できますか?

4

3 に答える 3

0

widgetNameとが同じである限り、次のようwidgetIdに判断できることがわかりました。widgetValue

function onFocusHighlight(e) {
  var app = UiApp.getActiveApplication();
  var widgetId = e.parameter.source;
  var widgetName = widgetId; // name MUST match id to retrieve widget value      
  var widgetValue = e.parameter[widgetName]; // not sure why this syntax works???

  var widget = app.getElementById(widgetId);  
  widget.setSelectionRange(0,widgetValue.length);  

  return app;
}

e.parameter[widgetName]私の唯一の問題は、構文が実際にどのように/なぜ機能するのかを理解することです。また、同じ価値に依存せず、同じ価値を持つソリューションがあれば素晴らしいと思いwidgetNameますwidgetId

于 2013-01-24T22:34:22.877 に答える
0

あなた自身の答えに続く単なる提案:

ID からウィジェット名を取得する変換テーブルをどこかに置くことで、おそらく機能させることができます。

たとえば、次のように定義できます。

  ScriptProperties.setProperties({'widgetID1':'Name1','widgetID2':'name2'},true)

その後

 widgetvalue = e.parameter[ScriptProperties.getProperty(e.parameter.source)]

私はこのコードをテストしませんでしたが、論理的に思えます ;-)、そうでない場合は教えてください (今はテストする時間がありません)

編集:期待どおりに動作します。結果を表示するテストシート、以下のテストコードです。

function Test(){
  var app = UiApp.createApplication().setTitle('test');
  app.add(app.createLabel('Type anything in upper textBox and then move your mouse over it...'))
  var p = app.createVerticalPanel()
  var txt1 = app.createTextBox().setId('txt1').setName('Name1').setValue('value in TextBox1')
  var txt2 = app.createTextBox().setId('txt2').setName('Name2').setValue('waiting to mouseOver textBox1')
  p.add(txt1).add(txt2)
  app.add(p)
  var handler = app.createServerHandler('mouseOver').addCallbackElement(p);
  txt1.addMouseOverHandler(handler); 
  ScriptProperties.setProperties({'txt1':'Name1','txt2':'Name2'},true);//save the name, only txt1 will be used here  
  var ss=SpreadsheetApp.getActiveSpreadsheet()
ss.show(app)
}

function mouseOver(e) {
  var app = UiApp.getActiveApplication();
  var widget = app.getElementById(e.parameter.source);
  var widgetValue = e.parameter[ScriptProperties.getProperty(e.parameter.source)]; // ScriptProperties knows the Widget's name 
  app.getElementById('txt2').setValue(widgetValue) ;// Use the other widget to show result
  return app;
}
于 2013-01-24T22:59:12.510 に答える
0

var widget = app.getElementById(e.parameter.source).setName("widgetName")

次に、widgetValue を取得します。

var widgetValue = e.parameter.widgetName

の使用方法については、https://developers.google.com/apps-script/uiappを確認してくださいsetName

于 2013-01-24T13:21:50.780 に答える