0

「blocksSizeList」と「briquettesSizeList」の項目をフレックステーブルに追加すると問題が発生します。たとえば、「blocksSizeList」を無視し、非表示の場合でも「briquettesSizeList」からアイテムのみを追加します。これはどのように修正できますか?

function doGet(e) {
      var app = UiApp.createApplication();

     //Create horizontal product + other panel
      var productOtherPanel = app.createHorizontalPanel().setId('productOtherPanel')
      .setStyleAttribute('position','relative').setStyleAttribute('left','0%');

      //Create horizontal Product Panel  
      var productPanel = app.createHorizontalPanel().setId('productPanel').setStyleAttribute('position','relative')
      .setStyleAttribute('left','0%').setVisible(true);
      //Create listBox
      var productList = app.createListBox().setName("productList").setId('productList');
      //Add items to listBox
      productList.addItem("8:1 Compressed Blocks");
      productList.addItem("8:1 Compressed Briquettes");

      var handlerC = app.createServerHandler("panelHandler");
      productList.addChangeHandler(handlerC);

      //Create horizontal Compressed Blocks panel
      var blocksPanel = app.createHorizontalPanel().setId('blocksPanel')
      .setStyleAttribute('position','relative').setStyleAttribute('left','0%').setVisible(true);
      //Create Compressed Blocks Size List
      var blocksSizeList = app.createListBox().setName('blocksSizeList').setId('blocksSizeList');
      //addItem fills the Compressed Blocks Size List
      blocksSizeList.addItem("5kg");
      blocksSizeList.addItem("20kg");

      //Create horizontal Briquettes panel
      var briquettesPanel = app.createHorizontalPanel().setId('briquettesPanel')
      .setStyleAttribute('position','relative').setStyleAttribute('left','0%').setVisible(false);
      //Create Briquettes Size List
      var briquettesSizeList = app.createListBox().setName('briquettesSizeList').setId('briquettesSizeList');
      //addItem fills the Briquettes Size List
      briquettesSizeList.addItem("250g");
      briquettesSizeList.addItem("650g");

      //Create hidden app      
      var hidden = app.createHidden().setName('hidden').setId('hidden').setValue('1')
      //Create button handler
      var handlerB = app.createServerHandler("buttonHandler");
      // pass the listbox into the handler function as a parameter and the hidden widget as well
      handlerB.addCallbackElement(productList).addCallbackElement(hidden);
      handlerB.addCallbackElement(blocksSizeList).addCallbackElement(hidden);
      handlerB.addCallbackElement(briquettesSizeList).addCallbackElement(hidden);

      //Create flextable 
      var quotesFlexTable = app.createFlexTable().setId("quotesFlexTable")
      .setStyleAttribute('position','relative').setStyleAttribute('left','0%');

      //Create flex table style attributes
        quotesFlexTable.setStyleAttribute("border-style", "solid");
        quotesFlexTable.setStyleAttribute("border-width", "1px");  
        quotesFlexTable.setCellPadding(5);



      //Create flex table headers  
      quotesFlexTable.setWidget(0, 0, app.createLabel("Product Type")).setStyleAttribute("color", "blue");
      quotesFlexTable.setWidget(0, 1, app.createLabel("Size")); 

      var button = app.createButton("+", handlerB);

      // add all widgets to the app

      //Add all widgets to the app




      app.add(quotesFlexTable).add(hidden);
      app.add(productOtherPanel);
      productOtherPanel.add(productPanel);
      productPanel.add(productList);
      productOtherPanel.add(blocksPanel);
      blocksPanel.add(blocksSizeList);
      productOtherPanel.add(briquettesPanel);
      briquettesPanel.add(briquettesSizeList);
      productOtherPanel.add(button);


      return app;
    }

    function buttonHandler(e) {
      var app = UiApp.getActiveApplication();
      // get the position (is a string)
      var pos = e.parameter.hidden;
      // initial condition, hidden widget is empty
      // convert to number
       pos=Number(pos);
      var quotesFlexTable = app.getElementById("quotesFlexTable");
      // add the new item at the right place
      quotesFlexTable.insertRow(pos).insertCell(pos, 0).setText(pos, 0, e.parameter.productList)
      .setText(pos, 1, e.parameter.blocksSizeList).setText(pos, 1, e.parameter.briquettesSizeList);
      // increment position
      ++pos;
      // save value
      app.getElementById('hidden').setValue(pos);
      // update app
      return app;
      }

    function panelHandler(event) {
      var app = UiApp.getActiveApplication();
      if (event.parameter.productList == "8:1 Compressed Blocks") {
        app.getElementById('blocksPanel').setVisible(true);
        app.getElementById('briquettesPanel').setVisible(false);
      }
      else if (event.parameter.productList == "8:1 Compressed Briquettes") {
        app.getElementById('blocksPanel').setVisible(false);
        app.getElementById('briquettesPanel').setVisible(true);
      }
      return app;
    }
4

1 に答える 1

0

buttonHandler 関数でフレックス テーブル セルを 2 回設定しています。2 回目は常に 1 回目を上書きするため、追加された練炭のサイズのみが表示されます。次のように変更します。

if (e.parameter.productList == "8:1 Compressed Blocks") {
  quotesFlexTable.insertRow(pos).insertCell(pos, 0).setText(pos, 0, e.parameter.productList).setText(pos, 1, e.parameter.blocksSizeList);
    }
else {
  quotesFlexTable.insertRow(pos).insertCell(pos, 0).setText(pos, 0, e.parameter.productList).setText(pos, 1, e.parameter.briquettesSizeList);
}
于 2012-11-28T15:57:32.947 に答える