我有很多个工具条,我需要遍历每个工具条,然后读取每个工具上对应控件的信息。
首先,我每生成一个工具条,将工具条对象放入一个数组中,然后遍历该数组中的每一个工具条。
var _toolBar=[];//工具条数组
//新建工具条
function addNewToolbar(){
var tb = new Ext.Toolbar();
tb.render('toolbar');
//取消按钮
var deleteBtn = {
text:'取消',
iconCls: 'clsmenu',
handler:function (){//取消该工具条
if(_toolBar.length<2){return;}
for(var i=0;i<_toolBar.length;i++){
if (_toolBar[i]==tb){
_toolBar.remove(_toolBar[i]);//从工具条数组中移除
}
}
tb.destroy();//销毁此工具条
}
};
//增加按钮
var addBtn = {text:'增加',iconCls: 'clsmenu',handler:function(){
var tempTool = addNewToolbar();
_toolBar.push(tempTool);//添加到工具条数组中
}
};
//文本框
var inputField = new Ext.form.TextField({name:'text'});
tb.add(inputField,'-',addBtn,deleteBtn);
tb.doLayout();
return tb;
}
在新建工具条的时候要将工具条放入数组
_toolBar.push(addNewToolbar());
遍历工具条条数组
for (var i = 0; i < _toolBar.length; i++) {
var tool = _toolBar[i];
for(var j=0;j<tool.items.length;j++){
//遍历工具条上的每个控件
var t = tool.items.get(j);
//打印控件的值
console.log(t.getValue());
/*
//这里是拿ID来识别我具体的控件
if(tool.items.get(j).getId().substr(0,10)=='idcombreal'){
if(tool.items.get(j).getValue()==''){
rst={title:'错误',text:'请选择条件!'}
return rst;
}
if(tool.items.get(j).getValue()=='must'){
rst = a_real_cdt(must_cdt,tool);//将该tool上的信息放入must_cdt数组中
}else if(tool.items.get(j).getValue()=='must_not'){
rst = a_real_cdt(must_not_cdt,tool);//将该tool上的信息放入must_not数组中
}else if(tool.items.get(j).getValue()=='should'){
rst = a_real_cdt(must_not_cdt,tool);//将该tool上的信息放入should数组中
}
}
*/
}
//return rst;
}