Zk 中 兩列 listbox資料轉移,並獲得 listbox中的值
阿新 • • 發佈:2018-12-30
<hlayout height="160px" width="260px"> <listbox id="candidateLb" hflex="1" vflex="true" multiple="true" rows="8"> <listhead> <listheader label="合同成品" width="80px" ></listheader> </listhead> </listbox> <vbox spacing="10px" width="24px"> <image style="cursor:pointer" id="chooseAllBtn" src="/img/rightrightarrow_g.png" /> <image style="cursor:pointer" id="chooseBtn" src="/img/rightarrow_g.png" /> <image style="cursor:pointer" id="removeBtn" src="/img/leftarrow_g.png" /> <image style="cursor:pointer" id="removeAllBtn" src="/img/leftleftarrow_g.png" /> </vbox> <listbox id="chosenLb" hflex="1" vflex="true" multiple="true" rows="8"> <listhead> <listheader label="已選成品" width="80px"></listheader> </listhead> <template name="model"> <listitem> </listitem> </template> </listbox> </hlayout>
java頁面處理
public void onClick$chooseBtn() throws Exception{ if(candidateLb.getSelectedIndex()<0) { MyMessagebox.info("請選中合同成品資料."); return; } String files=this.candidateLb.getSelectedItem().getValue(); candidateLb.removeItemAt(candidateLb.getSelectedIndex()); chosenLb.appendItem(files,files); } public void onClick$removeBtn() throws Exception{ if(chosenLb.getSelectedIndex()<0){ MyMessagebox.info("請選中已選成品資料."); return; } String files=this.chosenLb.getSelectedItem().getValue(); chosenLb.removeItemAt(chosenLb.getSelectedIndex()); candidateLb.appendItem(files,files); } public void onClick$chooseAllBtn() throws Exception{ if(lstcontractno.getSelectedIndex()<0) return; chosenLb.getItems().clear(); String parax=lstcontractno.getSelectedItem().getValue().toString().toUpperCase(); JdbcDao dao=JdbcFactory.getDgWofeJdbcDao(plant); String sql=" select sequenceno||'.'||itemno as consumelst from ct_t_contractitem where class='0' AND contractid='"+parax+"'"; ArrayList<LinkedHashMap> lstRet= dao.query(sql); for(LinkedHashMap map: lstRet){ chosenLb.appendItem((String)map.get("CONSUMELST"),(String)map.get("CONSUMELST")); } candidateLb.getItems().clear(); } public void onClick$removeAllBtn() throws Exception{ onSelect$lstcontractno(); //查詢出來的所有資料 chosenLb.getItems().clear(); }
獲得已選資料的筆數 this.chosenLb.getItems().size();
獲得已選資料 (因我的資料是兩個欄位合成,所有有進行字元擷取)
String sequence_no="",item_no="";
List<Listitem> list = this.chosenLb.getItems();
if(list != null){
int index = 0;
double c = ((double) list.size())/5;
index=(int) Math.ceil(c);
for(int i = 0; i < list.size(); i++){
String itemx = list.get(i).getValue();
String a[] = itemx.split("\\."); //擷取字串
if(i < list.size()-1){
sequence_no+="'"+a[0]+"',";
item_no+="'"+a[1]+"',";
}else{
sequence_no+="'"+a[0]+"'";
item_no+="'"+a[1]+"'";
}
}
}