dannyr's Blog
ColdFusion Delphi Flex Java .Net —— 一个都不能少!
博客园
社区
首页
新随笔
联系
管理
订阅
随笔- 93 文章- 3 评论- 316
Spry Framework入门(四)——XML数据集排序
简介
:
Spry Framework是Adobe出品的轻量级的支持Ajax的JavaScript库,以HTML为中心,使用最基本的HTML、CSS和JavaScript来实现丰富Web页面体验。
本例子演示了数据集的字段排序功能以及对数据集排序时候触发的事件的处理;代码很简单,需要讲一下sort方法,sort方法有2个入口参数:字段名和排序顺序(ascending descending toggle),前面一个就是需要排序的字段名称,第二个是指示排序顺序(从小到大还是从大到小),其中toggle为本次排序是否和上次反序,比如当前数据集按字段1升序排序,那调用sort方法后则按降序排序,反之亦然。还有一个是排序字段的数据类型,默认的Spry都是按字符串string类型排序,另外Spry提供了数字number和日期date,一共3种数据排序类型。如设置字段为数字类型:dsPhotos.setColumnType("@width", "number");
顺便做了个数据交替显示的功能。
试验环境
:
操作系统:windowsXP Sp2
浏览器:FireFox 2.0
WEB服务器:IIS 5.0
Spry库:Spry_P1_3_08-11
安装
:
从
http://labs.adobe.com/technologies/spry/
下载安装包,目前版本为Spry_P1_3_08-11.zip,解开后把includes目录复制到自己的IIS虚拟目录上即可。
页面代码
:
test.html
1
<!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
2
<
html
xmlns
="http://www.w3.org/1999/xhtml"
xmlns:spry
="http://ns.adobe.com/spry"
>
3
<
head
>
4
<
meta
http-equiv
="Content-Type"
content
="text/html; charset=iso-8859-1"
/>
5
<
title
>
Static Table Sample
</
title
>
6
<
script
type
="text/javascript"
src
="includes/xpath.js"
></
script
>
7
<
script
type
="text/javascript"
src
="includes/SpryData.js"
></
script
>
8
9
<
script
type
="text/javascript"
>
10
//
var dsEmployees = new Spry.Data.XMLDataSet("data/employees-01.xml", "employees/employee");
11
var
dsEmployees
=
new
Spry.Data.XMLDataSet(
"
data/employees-01.xml
"
,
"
employees/employee
"
,
{ sortOnLoad:
"
@id
"
, sortOrderOnLoad:
"
ascending
"
}
);
12
13
var
myObserver
=
new
Object;
14
15
myObserver.onPreSort
=
function
(dataSet, data)
{
16
//
alert("onPreSort called!");
17
var
info
=
document.getElementById(
"
info
"
);
18
info.innerHTML
=
"
<table><tr><th>Last Sort Columns</th><th>Sort Order</th></tr><tr><td>
"
+
data.oldSortColumns
+
"
</td><td>
"
+
data.oldSortOrder
+
"
</td></tr></table>
"
;
19
20
info.innerHTML
+=
"
<table><tr><th>New Sort Columns</th><th>Sort Order</th></tr><tr><td>
"
+
data.newSortColumns
+
"
</td><td>
"
+
data.newSortOrder
+
"
</td></tr></table>
"
;
21
}
;
22
23
myObserver.onPostSort
=
function
(dataSet, data)
{
24
//
alert("onPostSort called!");
25
}
;
26
27
28
dsEmployees.addObserver(myObserver);
29
30
31
</
script
>
32
33
<
style
>
34
35
.even
{
}
{
36
background-color
:
#eeeeee
37
}
38
39
.odd
{
}
{
40
background-color
:
#ffffff
;
41
}
42
43
</
style
>
44
45
</
head
>
46
<
body
>
47
48
<
div
spry:region
="dsEmployees"
>
49
<
table
border
="1"
>
50
<
tr
>
51
<
th
scope
="col"
>
Employee ID
</
th
>
52
<
th
scope
="col"
>
Last Name
</
th
>
53
<
th
scope
="col"
>
First Name
</
th
>
54
<
th
scope
="col"
>
Phone
</
th
>
55
<
th
scope
="col"
>
Username
</
th
>
56
</
tr
>
57
<
tr
spry:repeat
="dsEmployees"
class
="{ds_EvenOddRow}"
>
58
<
td
>
{@id}
</
td
>
59
<
td
>
{lastname}
</
td
>
60
<
td
>
{firstname}
</
td
>
61
<
td
>
{phone}
</
td
>
62
<
td
>
{username}
</
td
>
63
</
tr
>
64
</
table
>
65
66
67
</
div
>
68
<
hr
>
69
<
input
type
=button
value
="Sort by ID"
onclick
="dsEmployees.sort('@id', 'toggle');"
>
70
<
input
type
=button
value
="Sort by Last Name"
onclick
="dsEmployees.sort('lastname', 'toggle');"
>
71
<
br
>
72
<
div
id
="info"
/>
73
</
body
>
74
</
html
>
employees-01.xml
1
<?
xml version="1.0" encoding="iso-8859-1"
?>
2
<
employees
xmlns
="http://www.foo.com/employees"
>
3
<
employee
id
="123456"
>
4
<
lastname
>
Smith
</
lastname
>
5
<
firstname
>
Edward
</
firstname
>
6
<
phone
>
(415) 333-0235
</
phone
>
7
<
username
>
esmith
</
username
>
8
</
employee
>
9
<
employee
id
="127937"
>
10
<
lastname
>
Johnson
</
lastname
>
11
<
firstname
>
Neil
</
firstname
>
12
<
phone
>
(415) 333-9475
</
phone
>
13
<
username
>
njohnson
</
username
>
14
</
employee
>
15
<
employee
id
="126474"
>
16
<
lastname
>
Williams
</
lastname
>
17
<
firstname
>
Steve
</
firstname
>
18
<
phone
>
(415) 333-4573
</
phone
>
19
<
username
>
swilliams
</
username
>
20
</
employee
>
21
<
employee
id
="120585"
>
22
<
lastname
>
Jones
</
lastname
>
23
<
firstname
>
John
</
firstname
>
24
<
phone
>
(415) 333-9345
</
phone
>
25
<
username
>
jjones
</
username
>
26
</
employee
>
27
<
employee
id
="127493"
>
28
<
lastname
>
Brown
</
lastname
>
29
<
firstname
>
Joe
</
firstname
>
30
<
phone
>
(415) 333-5938
</
phone
>
31
<
username
>
jbrown
</
username
>
32
</
employee
>
33
</
employees
>
34
posted @ 2006-10-26 15:52
dannyr|一个都不能少!
阅读(1990)
评论(2)
编辑
收藏
所属分类:
Spry
发表评论
回复
引用
#1楼
2007-03-15 21:59 |
zltang [未注册用户]
请问为什么中文的不能显示和排序
回复
引用
#2楼
2007-03-19 08:44 |
dannyr [未注册用户]
应该是字符集的缘故,中文是可以显示并排序的!
新用户注册
刷新评论列表
标题
姓名
主页
Email
(博主才能看到)
验证码
*
看不清,换一张
[
登录
][
注册
]
内容(请不要发表任何与政治相关的内容)
网站首页
新闻频道
社区
小组
博问
网摘
闪存
找找看
Remember Me?
登录
使用高级评论
新用户注册
返回页首
恢复上次提交
[使用Ctrl+Enter键可以直接提交]
该文被作者在 2006-10-26 16:11 编辑过
"五向定位"职业成长路线公开课(上海、南京、大连)
Google站内搜索
相关文章:
使用Visual Studio2005入门.Net2.0系列视频教程
ASP.NET AJAX入门系列
相关链接:
历史上的今天:
2004-10-26
秋夜寄邱二十二员外
2004-10-26
不基于NTFS权限的CVSNT权限设置
所属分类的其他文章:
检测浏览器类型的js
Spry1.4 下载
Spry PreRelease 1.4 发布
Spry Framework入门(五)——数据集过滤及淡入淡出效果
关于JSON
Spry Framework入门(四)——XML数据集排序
Spry Framework入门(三)——框架结构
Spry Framework入门(二)——XML数据集及主从表显示
Spry Framework入门(一)——XML数据集及显示
最新IT新闻:
微型博客Twitter取消IM服务 称其ROI差
用手机聊Gtalk的方法以及应用总结
Google开拓美政府机构市场 微软业务受冲击
消息称苹果正在开发iTunes网络电视
微软周一开电话会议 预计将发布Silverlight2.0
公告
我的联系方式:
MSN dannyr@163.com
QQ 563178
20060606新计数器
Detail
<
2006年10月
>
日
一
二
三
四
五
六
24
25
26
27
28
29
30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
与我联系
发短消息
搜索
常用链接
我的随笔
我的空间
我的短信
我的评论
更多链接
我的参与
我的新闻
最新评论
我的标签
留言簿
给我留言
查看留言
随笔分类
.Net技术(22)
(rss)
C++(9)
(rss)
ColdFusion(5)
(rss)
Delphi(2)
(rss)
DevExpress(1)
(rss)
Flex技术(29)
(rss)
Java(4)
(rss)
Laszlo(9)
(rss)
Spry(9)
(rss)
生活随笔(10)
(rss)
杂项(13)
(rss)
随笔档案
2008年6月 (1)
2008年5月 (2)
2007年9月 (2)
2007年8月 (1)
2007年7月 (3)
2007年1月 (1)
2006年12月 (2)
2006年11月 (1)
2006年10月 (6)
2006年9月 (1)
2006年8月 (4)
2006年7月 (1)
2006年6月 (4)
2006年5月 (4)
2006年4月 (2)
2006年1月 (1)
2005年12月 (1)
2005年11月 (1)
2005年10月 (2)
2005年8月 (1)
2005年7月 (1)
2005年6月 (1)
2005年5月 (1)
2005年4月 (1)
2005年3月 (2)
2005年2月 (1)
2005年1月 (3)
2004年12月 (9)
2004年11月 (9)
2004年10月 (9)
2004年9月 (3)
2004年8月 (2)
2004年7月 (6)
2004年6月 (4)
文章分类
ColdFusion
(rss)
Flex技术(3)
(rss)
文章档案
2004年6月 (3)
我的链接
Trademan
(rss)
www.k-zone.cn
(rss)
呼呼堂
(rss)
牛皮糖
(rss)
最新评论
阅读排行榜
1. 任意对象数组ArrayList的排序法(可自定义排序字段、排序方向)(8666)
2. ASP.NET动态加载用户控件的页面生成过程(8644)
3. 征集比较完善的权限管理方案!(最好有C#方案)(6285)
4. 关于上个Flex-Jsp-DB例子中Flex和Jsp传递中文参数问题的解决方法!(Tomcat服务器)(5778)
5. 贴个Flex-Jsp-Mysql简单结合例子(5478)
6. Flex2.0文件上传功能(Flex2.0正式版)(5410)
7. Flex RemoteObject 简单应用Demo(5202)
8. DeKlarit:一个不错的top-down CG工具(4637)
9. Rich Client Fashion(转载)+乱弹(4457)
10. Flex2.0实现文件上传功能(服务器为ASP.NET)(4031)
评论排行榜
1. DeKlarit:一个不错的top-down CG工具(24)
2. 关于上个Flex-Jsp-DB例子中Flex和Jsp传递中文参数问题的解决方法!(Tomcat服务器)(17)
3. Flex2.0实现文件上传功能(服务器为ASP.NET)(17)
4. 如何关闭子线程?征集析构函数与多线程的讨论!(16)
5. 神影无踪-廖添丁FlashGame(15)
6. 征集比较完善的权限管理方案!(最好有C#方案)(13)
7. 贴个Flex-Jsp-Mysql简单结合例子(11)
8. ASP.NET动态加载用户控件的页面生成过程(11)
9. 体验 Delphi2005's ECO II 空间技术(10)
10. Flex2.0文件上传功能(Flex2.0正式版)(10)