2013-01-10 5 views
1

선택한 항목을 목록, 콤보 상자 등으로 가져 오는 방법은 무엇입니까? 목록 상자에서 선택한 값 가져 오기?

나는 코드 here의이 비트 발견

/***** 
*** 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'); 

를하지만 목록 상자에서 모든 항목뿐 아니라 선택한 사람을 얻을 것으로 보인다. 모든 아이디어를 수정하여 선택한 값만 가져 오는 방법은 무엇입니까?

답변

1

당신은 SSJS로 선택된 값에 액세스 할 수 있습니다

getComponent('comboBox1').value 

가 활성화되어있는 목록 상자 및 다중 선택하여 작업하는 경우, 당신은 문자열의 배열을 가져 오는 폭발 사용할 수 있습니다

@Explode(getComponent('listBox1').value) 
+0

감사합니다. 트릭을 한 것은 @explode라고 생각합니다. –

2

구성 요소에 묻는 대신 데이터 모델에 요청하십시오. 예를 들어, 목록 상자에 바인딩 된 경우 :

#{someDoc.someItemName} 

... 당신은 데이터 소스 요청에 의해 선택된 값을 검색 할 수 있습니다 구성 요소가 대신 스코프에 바인딩되어있는 경우

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

을 변수 :

var selectedValues = viewScope.get("selectedValues"); 
,691 :

#{viewScope.selectedValues} 

... 다음 그냥 변수를 물어

+0

상자가 데이터 모델에 연결되어있는 경우 더 나은 방법입니다. –

관련 문제