Adobe Flex 日期字段
我有一些代码如下:
private function onComboChange(evt:Event):void {
var temp:Date = df_date.selectedDate;
temp.date += 5;
df_dateDue.selectedDate = new Date(temp);
}
本质上,我试图在 df_date 中的选定日期上添加 5 天,并将该日期放入 df_dateDue 中。这通过组合框上的事件监听器触发。 df_date 和 df_dateDue 都是日期字段。
好的,所以我第一次运行它时,它工作得很好; df_date 保持不变,df_dateDue 设置为 df_date 过去 5 天。但是,下次运行它时,df_dateDue 从 df_date 开始增加 10 天,下一次则增加 15 天,依此类推。
因此,单步执行代码表明 df_date 已以某种方式链接到临时变量,并且临时变量不会在每次调用函数时重置自身。
示例:df_date = 01 Jan,df_dateDue = 01 Jan。
触发事件,df_date = 01 Jan,df_dateDue = 06 Jan
再次关闭活动。此时,var temp = 06 Jan(尽管 df_date 仍显示 01 Jan),然后 df_dateDue 设置为 11 Jan
再次触发事件。此时 var temp = 11 Jan(即使 df_date = 01 Jan),然后 df_dateDue 设置为 16 Jan
我在这里缺少什么?
I have some code as follows:
private function onComboChange(evt:Event):void {
var temp:Date = df_date.selectedDate;
temp.date += 5;
df_dateDue.selectedDate = new Date(temp);
}
In essence, I am trying to add 5 days onto the selected date in df_date, and put that date into df_dateDue. This fires off via an EventListener on a combobox. Both df_date and df_dateDue are dateFields.
OK, so the first time that I run this, it works fine; df_date stays the same and df_dateDue is set to 5 days past df_date. However, the next time that I run it, df_dateDue increments by 10 days from df_date, the next time by 15, and so on.
So, stepping through the code shows that somehow df_date has become linked to the temp var, and that the temp var is not resetting itself each time the function is called.
Example: df_date = 01 Jan, df_dateDue = 01 Jan.
Fire off the event, df_date = 01 Jan, df_dateDue = 06 Jan
Fire off the event again. At this point, var temp = 06 Jan (even though df_date still shows 01 Jan), and df_dateDue is then set to 11 Jan
Fire off the event again. At this point var temp = 11 Jan (even though df_date = 01 Jan), and df_dateDue is then set to 16 Jan
What am I missing here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Flex/AS 中,包含对象的变量实际上只是指向某些内存空间的指针。 Flex 中的日期是对象,而不是本机类型。此行:
创建一个指向现有日期对象的新指针。它不会创建副本。
此行:
递增 dateObject 的日期属性。所有指向该日期对象的引用都将被更新。尝试使用 objectUtil.copy
In Flex/AS, variables that contain objects are really just pointers to some memory space. Date's in Flex are an Object, not a native type. This line:
Creates a new pointer to an existing date object. It does not create a copy.
This line:
increments the date property of the dateObject. All references pointing to that date object will be updated. Try using objectUtil.copy