1

選択したアイテムがリスト、コンボボックスなどであるようにするにはどうすればよいですか?

私はここでこのコードを見つけました:

/*****
 *** getSelectableValues()
 *** prints all selectable values for a given component, f.e. comboboxes, listboxes etc.
 ***
 *** @params id of component
 *****/

function getSelectableValues( id ) {
   var ComboBox = getComponent( id );
   var ChildrenList:java.util.ListIterator;
   ChildrenList = ComboBox.getChildren().listIterator();
   while (ChildrenList.hasNext()) {
      var Child = ChildrenList.next();

      /*** process computed / multiple values ***/
      if( typeof( Child ) == 'com.ibm.xsp.component.UISelectItemsEx' ){
         var hlp = Child.getValue();
         for( var i=0; i< hlp.length; i++ ){

            /*** print to server console ***/
            print( hlp[i].getLabel() + "|" + hlp[i].getValue() );
         }
      }

      /*** process single values ***/
      if( typeof( Child ) == 'com.ibm.xsp.component.UISelectItemEx' ){

      /*** print to server console ***/
      print( Child.getItemLabel() + "|" + Child.getItemValue() );
      }
   }
}

/*** get all selectable values for element 'comboBox1' ***/
getSelectableValues( 'comboBox1' );

ただし、選択したアイテムだけでなく、リストボックス内のすべてのアイテムを取得しているようです。選択した値だけを取得するように変更する方法はありますか?

4

2 に答える 2

2

コンポーネントに尋ねる代わりに、データモデルに尋ねます。たとえば、リストボックスが次の場所にバインドされている場合:

#{someDoc.someItemName}

...次に、データソースに問い合わせることで、選択した値を取得できます。

var selectedValues = someDoc.getValue("someItemName");

コンポーネントが代わりにスコープ変数にバインドされている場合:

#{viewScope.selectedValues}

...次に、その変数を尋ねます。

var selectedValues = viewScope.get("selectedValues");
于 2013-01-10T14:14:31.547 に答える
1

SSJSを使用して、選択した値にアクセスできます。

getComponent('comboBox1').value

リストボックスを使用していて、複数選択が有効になっている場合は、Explodeを使用して文字列の配列を取得できます。

@Explode(getComponent('listBox1').value)
于 2013-01-10T13:56:23.680 に答える