Flex 属性在 HTTPService 中使用时表现奇怪
我正在使用 REST 请求编写 Flex 应用程序,并尝试避免 HTTP 缓存以及同步客户端/服务器时间。 为此,我创建了一个 timestamp
属性,如下所示:(
// returns a timestamp corrected for server time
private function get timestamp() : Number
{
return new Date().getTime() + clientClockAdjustMsec;
}
我已经使用特殊的 mojo 设置了 clientClockAdjustMsec
)
我还尝试在查询字符串中包含时间戳像这样:
<mx:HTTPService url="/Service?ts={timestamp}" ...
但是我在访问日志中看到的很奇怪。 它是这样的:
1.2.3.4 - - [06/Aug/2009:17:19:47 +0000] "GET /Service?ts=1249579062937 HTTP/1.1" 200 478
1.2.3.4 - - [06/Aug/2009:17:20:13 +0000] "GET /Service?ts=1249579062937 HTTP/1.1" 200 500
1.2.3.4 - - [06/Aug/2009:17:20:14 +0000] "GET /Service?ts=1249579062937 HTTP/1.1" 200 435
看看时间戳是如何相同的? 这么奇怪。 我希望它每次都会评估该属性,就像它对可绑定变量所做的那样。
(实际上,我刚刚再次检查了一下,它确实对可绑定变量执行了相同的操作。但并非对所有客户端都有效。某些版本的 Flash 有“问题”吗?)
I'm writing a Flex app using REST requests and trying to avoid HTTP caching as well as synchronize client/server time. To this end I've created a timestamp
property as such:
// returns a timestamp corrected for server time
private function get timestamp() : Number
{
return new Date().getTime() + clientClockAdjustMsec;
}
(The clientClockAdjustMsec
I've already set using special mojo)
I also attempt to include the timestamp in my query string like this:
<mx:HTTPService url="/Service?ts={timestamp}" ...
But what I see in the access logs is weird. It's something like this:
1.2.3.4 - - [06/Aug/2009:17:19:47 +0000] "GET /Service?ts=1249579062937 HTTP/1.1" 200 478
1.2.3.4 - - [06/Aug/2009:17:20:13 +0000] "GET /Service?ts=1249579062937 HTTP/1.1" 200 500
1.2.3.4 - - [06/Aug/2009:17:20:14 +0000] "GET /Service?ts=1249579062937 HTTP/1.1" 200 435
See how the timestamps are all the same? So strange. I would expect it to evaluate the property every time, as it does for Bindable variables.
(Actually, I just checked again and it does do the same thing for Bindable variables. But not with all clients. Do some versions of Flash have "issues"?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
所以这是一个只读吸气剂? 绑定不会更新 HTTPService 组件中的 {timestamp},因为它没有要绑定的属性。 时间戳是函数的输出(正如 Christopher 在下面提到的),并且不是可绑定属性。 您需要创建一个可绑定属性,或者使用当前时间戳显式设置 URL,从而完全避免绑定。
在代码中的某个地方您正在使用 myService.send(),您需要执行以下操作:
如果由于某种原因不起作用:
从而避免任何绑定问题...
so this is a read only getter? Binding isn't going to update {timestamp} in your HTTPService component as it has no property to bind to. timestamp is the output of a function (as Christopher mentions below) and is not a Bindable property. You need to either create a bindable property, or explicitly set the URL with a current timestamp, avoiding binding altogether.
Someplace in your code you are using myService.send(), you need to do something like:
if for some reason that didn't work:
thus avoiding any binding issues...
您可以做的另一件事是使 get 函数可绑定到特定事件。
The other thing you can do is make the get function bindable to a specific event.