网速质素不高.....
继续数组吧,之前我在使用时出现了一些错误,但语法又没问题,最后发现是在代码中使用了中文的字符,相当无语。NetBeans的功能有待加强,反正我是觉得没有myeclipse舒服,懒啦。
[b]修改数组:[/b]
除了赋值操作(=)之外,JavaFX 还提供数据修改操作符(insert 和delete)
insert语句
可以用下面方式中的任意一种进行声明:
[b]insert Expression1 [as first | as last] into Expression2
insert Expression1 before Expression2
insert Expression1 after Expression2[/b]
注意:Expression2必须指向一个属性或者变量。如果Expression2指向一个单值属性,那么插入的效果等同于赋值操作。as first指明在Expression2第一个元素前,as last相反。缺省设置为as last
var x = [1,2,3];
insert 12 into x; // yields [1,2,3,12]
insert 10 as first into x; // yields [10,1,2,3,12]
insert [99,100] as last into x; // yields [10,1,2,3,12,99,100]
另外还有更精确的插入方式before,after
Expression2必须是在属性或者变量之上的选择表达式。如果指定了before,那么插入位置就是在被选择的元素之前。如果指定了after,插入位置则在被选择的元素之后。
例如:
var x = [1,2,3];
insert 10 after x[. == 10]; // yields [1,2,3,10]
insert 12 before x[1]; // yields [1,12,2,3,10]
insert 13 after x[. == 2]; // yields [1, 12, 2, 13, 3, 10];
有了插入当然就有删除,关键字delete
[b]delete variable
delete Expression.attribute
delete variable[predicate]
delete Expression.attribute[predicate][/b]
前两种用法是赶尽杀绝全部赋值为null,后两种是指定元素或属性删除
var x = [1,2,3];
insert 10 into x; // yields [1,2,3,10]
insert 12 before x[1]; // yields [1,12,2,3,10]
delete x[. == 12]; // yields [1,2,3,10]
delete x[. >= 3]; // yields [1,2]
insert 5 after x[. == 1]; // yields [1,5,2];
insert 13 as first into x; // yields [13, 1, 5, 2];
delete x; // yields []
增删改查,现在JFX都提供了,别的不说JFX在重视数组操作上确实有优势..
select .... where用法
class Album {
attribute title: String;
attribute artist: String;
attribute tracks: String*;
}
var albums =
[Album {
title: "A Hard Day's Night"
artist: "The Beatles"
tracks:
["A Hard Day's Night",
"I Should Have Known Better",
"If I Fell",
"I'm Happy Just To Dance With You",
"And I Love Her",
"Tell Me Why",
"Can't Buy Me Love",
"Any Time At All",
"I'll Cry Instead",
"Things We Said Today",
"When I Get Home",
"You Can't Do That"]
},
Album {
title: "Circle Of Love"
artist: "Steve Miller Band"
tracks:
["Heart Like A Wheel",
"Get On Home",
"Baby Wanna Dance",
"Circle Of Love",
"Macho City"]
}];
// Get the track numbers of the albums' title tracks
// using the select operator:
var titleTracks =
select indexof track + 1 from album in albums,
track in album.tracks
where track == album.title; // yields [1,4]
// the same expressed using the foreach operator:
titleTracks =
foreach (album in albums,
track in album.tracks
where track == album.title)
indexof track + 1; // also yields [1,4]
开发指南上有这段代码例子,不知道为什么netbeans下无法识别in,郁闷...期待答案
继续数组吧,之前我在使用时出现了一些错误,但语法又没问题,最后发现是在代码中使用了中文的字符,相当无语。NetBeans的功能有待加强,反正我是觉得没有myeclipse舒服,懒啦。
[b]修改数组:[/b]
除了赋值操作(=)之外,JavaFX 还提供数据修改操作符(insert 和delete)
insert语句
可以用下面方式中的任意一种进行声明:
[b]insert Expression1 [as first | as last] into Expression2
insert Expression1 before Expression2
insert Expression1 after Expression2[/b]
注意:Expression2必须指向一个属性或者变量。如果Expression2指向一个单值属性,那么插入的效果等同于赋值操作。as first指明在Expression2第一个元素前,as last相反。缺省设置为as last
var x = [1,2,3];
insert 12 into x; // yields [1,2,3,12]
insert 10 as first into x; // yields [10,1,2,3,12]
insert [99,100] as last into x; // yields [10,1,2,3,12,99,100]
另外还有更精确的插入方式before,after
Expression2必须是在属性或者变量之上的选择表达式。如果指定了before,那么插入位置就是在被选择的元素之前。如果指定了after,插入位置则在被选择的元素之后。
例如:
var x = [1,2,3];
insert 10 after x[. == 10]; // yields [1,2,3,10]
insert 12 before x[1]; // yields [1,12,2,3,10]
insert 13 after x[. == 2]; // yields [1, 12, 2, 13, 3, 10];
有了插入当然就有删除,关键字delete
[b]delete variable
delete Expression.attribute
delete variable[predicate]
delete Expression.attribute[predicate][/b]
前两种用法是赶尽杀绝全部赋值为null,后两种是指定元素或属性删除
var x = [1,2,3];
insert 10 into x; // yields [1,2,3,10]
insert 12 before x[1]; // yields [1,12,2,3,10]
delete x[. == 12]; // yields [1,2,3,10]
delete x[. >= 3]; // yields [1,2]
insert 5 after x[. == 1]; // yields [1,5,2];
insert 13 as first into x; // yields [13, 1, 5, 2];
delete x; // yields []
增删改查,现在JFX都提供了,别的不说JFX在重视数组操作上确实有优势..
select .... where用法
class Album {
attribute title: String;
attribute artist: String;
attribute tracks: String*;
}
var albums =
[Album {
title: "A Hard Day's Night"
artist: "The Beatles"
tracks:
["A Hard Day's Night",
"I Should Have Known Better",
"If I Fell",
"I'm Happy Just To Dance With You",
"And I Love Her",
"Tell Me Why",
"Can't Buy Me Love",
"Any Time At All",
"I'll Cry Instead",
"Things We Said Today",
"When I Get Home",
"You Can't Do That"]
},
Album {
title: "Circle Of Love"
artist: "Steve Miller Band"
tracks:
["Heart Like A Wheel",
"Get On Home",
"Baby Wanna Dance",
"Circle Of Love",
"Macho City"]
}];
// Get the track numbers of the albums' title tracks
// using the select operator:
var titleTracks =
select indexof track + 1 from album in albums,
track in album.tracks
where track == album.title; // yields [1,4]
// the same expressed using the foreach operator:
titleTracks =
foreach (album in albums,
track in album.tracks
where track == album.title)
indexof track + 1; // also yields [1,4]
开发指南上有这段代码例子,不知道为什么netbeans下无法识别in,郁闷...期待答案