“Stab”是一个tabnavigator,我喜欢在navigatorcontent中访问数据网格中的id。我试过getchildbyname
它似乎无法找到datagrid“nc1,nc2等”并返回null。
private var pdg:String="nc";
private function stabAdd():void {
var dg1:DataGrid = new DataGrid();
var cn:NavigatorContent = new NavigatorContent();
stab.addElement(cn);
cn.label = "New Tab";
cn.name = "nct"+nu;
cn.id = "nct"+nu;
dg1.id = "nc"+nu;
dg1.name = "nc"+nu;
pdg = dg1.id; //set this as current datagrid
nu++;
var columns:Array = [];
var myDataGridColumn:DataGridColumn = new DataGridColumn("id");
myDataGridColumn.headerText = "ID";
myDataGridColumn.width = 40;
columns.push(myDataGridColumn);
myDataGridColumn = new DataGridColumn("username");
myDataGridColumn.headerText = "Name";
myDataGridColumn.width = 160;
.....
dg1.columns = columns;
cn.addElement(dg1);
stab.selectedIndex = stab.numChildren-1;
}
答案 0 :(得分:0)
容器只是我父母的术语..如何将所有DataGrids添加到数组中。然后您可以按ID搜索:
function findDataGrid(findID:String):DataGrid
{
var i:DataGrid;
for each(i in array)
{
if(i.id == findID) return i;
}
return null;
}