用DataGrid读入数据的几种方法
类别: Flash教程
这几天一直在学组件,学的不精通,看了一些东西大家也许早会了,也写出来给大家,看看,刚学到DataGrid组件,就说它了.高手免看.这个这个组件有什么用处就不说了,它就像一个表格,显示数据,这个东西学ASP.NET的一定听说过,功能很强大,我想在flash中也不会很弱吧.呵呵,那就切入正题,说一下DataGrid读入数据的几种方法.根据书上所说,其支持的数据类型有2个,对象数组和Recordset对象了.前面简单点就说前面的
1.拖入DataGrid组件到场景,命名mydg
2.定义数组
var mydp:Array = new Array();
mydp.addItem({name:"xzzhangg", sex:"男", age:20, work:"学生", qq:"64957997"});
mydp.addItem({name:"xzzhangg", sex:"男", age:20, work:"学生", qq:"64957997"});
mydp.addItem({name:"xzzhangg", sex:"男", age:20, work:"学生", qq:"64957997"});
mydp.addItem({name:"xzzhangg", sex:"男", age:20, work:"学生", qq:"64957997"});
mydp.addItem({name:"xzzhangg", sex:"男", age:20, work:"学生", qq:"64957997"});
mydp.addItem({name:"xzzhangg", sex:"男", age:20, work:"学生", qq:"64957997"});
mydp.addItem({name:"xzzhangg", sex:"男", age:20, work:"学生", qq:"64957997"});
mydp.addItem({name:"xzzhangg", sex:"男", age:20, work:"学生", qq:"64957997"});
mydp.addItem({name:"xzzhangg", sex:"男", age:20, work:"学生", qq:"64957997"});
mydp.addItem({name:"xzzhangg", sex:"男", age:20, work:"学生", qq:"64957997"});
mydp.addItem({name:"xzzhangg", sex:"男", age:20, work:"学生", qq:"64957997"});
mydp.addItem({name:"xzzhangg", sex:"男", age:20, work:"学生", qq:"64957997"});
3.利用DataProvider API传送数据
//DataProvider API 是一组方法和属性,数据源需要这些方法和属性才能使基于 List 的类与其通信。数组、记录集和数据集均实现此 API。您可以通过实现本文档中描述的所有方法来创建符合 DataProvider 的类。然后,基于列表的组件将能够使用该类作为数据提供程序。
mydg.dataProvider = mydp;
好了,简单的完成了,可以ctrl+enter看一下效果了,是不是有列表,如下
4.我们可以修改一下标题,英文的标题没中文看着顺眼
//定义标题
var columnHeader:Array = ["姓名", "性别", "年龄", "职业", "QQ"];
mydg.vScrollPolicy = "auto";//指定滚动条在需要时显示
for (var i = 0; i<columnHeader.length; i++) {
//修改指定列的标题
mydg.getColumnAt(i).headerText = columnHeader[i];
}
var columnHeader:Array = ["姓名", "性别", "年龄", "职业", "QQ"];
mydg.vScrollPolicy = "auto";//指定滚动条在需要时显示
for (var i = 0; i<columnHeader.length; i++) {
//修改指定列的标题
mydg.getColumnAt(i).headerText = columnHeader[i];
}
再次测试一下,是不是标题变成中文了,如下
希望对我们新手有帮助,高手看了别BS我,
var mydp:Array = new Array();
mydp.addItem({name:"xzzhangg", sex:"男", age:20, work:"学生", qq:"64957997"});
mydp.addItem({name:"xzzhangg", sex:"男", age:20, work:"学生", qq:"64957997"});
mydp.addItem({name:"xzzhangg", sex:"男", age:20, work:"学生", qq:"64957997"});
mydp.addItem({name:"xzzhangg", sex:"男", age:20, work:"学生", qq:"64957997"});
mydp.addItem({name:"xzzhangg", sex:"男", age:20, work:"学生", qq:"64957997"});
mydp.addItem({name:"xzzhangg", sex:"男", age:20, work:"学生", qq:"64957997"});
mydg.dataProvider = mydp;
var columnHeader:Array = ["姓名", "性别", "年龄", "职业", "QQ"];
mydg.vScrollPolicy = "auto";//指定滚动条在需要时显示
for (var i = 0; i<columnHeader.length; i++) {
//修改指定列的标题
mydg.getColumnAt(i).headerText = columnHeader[i];
}
mydp.addItem({name:"xzzhangg", sex:"男", age:20, work:"学生", qq:"64957997"});
mydp.addItem({name:"xzzhangg", sex:"男", age:20, work:"学生", qq:"64957997"});
mydp.addItem({name:"xzzhangg", sex:"男", age:20, work:"学生", qq:"64957997"});
mydp.addItem({name:"xzzhangg", sex:"男", age:20, work:"学生", qq:"64957997"});
mydp.addItem({name:"xzzhangg", sex:"男", age:20, work:"学生", qq:"64957997"});
mydp.addItem({name:"xzzhangg", sex:"男", age:20, work:"学生", qq:"64957997"});
mydg.dataProvider = mydp;
var columnHeader:Array = ["姓名", "性别", "年龄", "职业", "QQ"];
mydg.vScrollPolicy = "auto";//指定滚动条在需要时显示
for (var i = 0; i<columnHeader.length; i++) {
//修改指定列的标题
mydg.getColumnAt(i).headerText = columnHeader[i];
}
-= 资 源 教 程 =-
文 章 搜 索