Flex 属性在 HTTPService 中使用时表现奇怪

发布于 2024-07-30 13:19:22 字数 935 浏览 2 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

野心澎湃 2024-08-06 13:19:23

所以这是一个只读吸气剂? 绑定不会更新 HTTPService 组件中的 {timestamp},因为它没有要绑定的属性。 时间戳是函数的输出(正如 Christopher 在下面提到的),并且不是可绑定属性。 您需要创建一个可绑定属性,或者使用当前时间戳显式设置 URL,从而完全避免绑定。

在代码中的某个地方您正在使用 myService.send(),您需要执行以下操作:

[Bindable]
private var timestamp:Number;

private function whereSendHappens():void
{
    timestamp = new Date().getTime() + clientClockAdjustMsec;
    myService.send()
}

<mx:HTTPService url="/Service?ts={timestamp}" ...

如果由于某种原因不起作用:

private function whereSendHappens():void
{
    timestamp = new Date().getTime() + clientClockAdjustMsec;
    myService.url = "/Service?ts=" + timestamp;
    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:

[Bindable]
private var timestamp:Number;

private function whereSendHappens():void
{
    timestamp = new Date().getTime() + clientClockAdjustMsec;
    myService.send()
}

<mx:HTTPService url="/Service?ts={timestamp}" ...

if for some reason that didn't work:

private function whereSendHappens():void
{
    timestamp = new Date().getTime() + clientClockAdjustMsec;
    myService.url = "/Service?ts=" + timestamp;
    myService.send();
}

thus avoiding any binding issues...

世俗缘 2024-08-06 13:19:23

您可以做的另一件事是使 get 函数可绑定到特定事件。

[Bindable("updateTimestamp")]
public function get timestamp() : Number { ... }

public function whereSendHappens():void
{
    dispatchEvent(new Event("updateTimestamp")); // will cause the binding to fire
    myService.send();
}

The other thing you can do is make the get function bindable to a specific event.

[Bindable("updateTimestamp")]
public function get timestamp() : Number { ... }

public function whereSendHappens():void
{
    dispatchEvent(new Event("updateTimestamp")); // will cause the binding to fire
    myService.send();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文