未指定事件名称的可绑定函数
在 Flex 中使函数 Bindable 而不指定事件名称会产生什么效果?我已经在我的代码中完成了此操作,并且它似乎工作正常,没有任何关联事件(但是它确实生成了警告)。如果我从此类函数中删除绑定,它确实会影响代码,并且如果函数的返回值发生更改,则不会反映更改。
有人可以解释一下,即使没有任何与 [Bindable] 标签关联的事件,这样的 Bindable 函数如何以及为什么工作。
示例:
<mx:Image id="a" source="{getImage(1)}" useHandCursor="true" buttonMode="true" width="10" height="10" click="finalize(event)" autoLoad="true"/>
[Bindable] private var _ratingSelected:int;
[Bindable]
private function getImage(value:int):String
{
if (value <= _ratingSelected)
return 'images/hr/applicants/star_icon.png';
else
return 'images/hr/applicants/star_icon_dis.png';
}
如果我从此处的 getImage 函数中删除 Bindable 标记,则图像在运行时不会正确更新。请注意,这里 _ ratingSelected 是可绑定变量。尽管我没有任何与 getImage() 函数相关的事件,但使其可绑定似乎工作得很好。它是否会自动检测 _ ratingSelected 变量(可绑定)的变化并在运行时调用 getImage 函数?请赐教。
谢谢。
What is the effect of making a function Bindable in flex without specifying event name with it? I have done this in my code and it seems to be working alright without any associated event (however it does generate a warning). If I remove the binding from such functions it will does effect the code and doesnt reflect the changes if the return value from the function changes.
Could someone explain me , how and why such Bindable function work even without any event associated with [Bindable] tag.
Example:
<mx:Image id="a" source="{getImage(1)}" useHandCursor="true" buttonMode="true" width="10" height="10" click="finalize(event)" autoLoad="true"/>
[Bindable] private var _ratingSelected:int;
[Bindable]
private function getImage(value:int):String
{
if (value <= _ratingSelected)
return 'images/hr/applicants/star_icon.png';
else
return 'images/hr/applicants/star_icon_dis.png';
}
If I remove the Bindable tag from getImage function here, the image doesnt properly get updated at the run time. Please note that _ratingSelected is Bindable variable here. Even though I don't have any event associated with getImage() function, making it Bindable seems to be working just alright. Does it automatically detect changes to changes in _ratingSelected variable (which is bindable) and call the getImage function at run time? Kindly enlighten.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您未在 Binding 标记中指定事件名称时,它将使用事件“propertyChange”。这意味着每次框架从文档中获取“propertyChange”事件时,它都会尝试通过再次调用
getImage
来更新图像源。现在,当
_ ratingSelected
的值更新时,会在内部调度“propertyChange”事件,从而导致图像更新。请注意,这与
getImage
是否实际使用_atingSelected
生成其返回值无关。从数据绑定框架的角度来看,getImage
和_atingSelected
之间的唯一联系是“propertyChange”事件,它们都声称在各自的值发生更改时调度该事件(即使getImage
从未实际调度它)。When you don't specify an event name in the Binding tag, it uses the event "propertyChange". This means that every time the framework gets a "propertyChange" event from your document, it'll try to update the image source by calling
getImage
again.Now when the value of
_ratingSelected
is updated, a "propertyChange" event is dispatched internally, which then causes the image to be updated.Note that this has nothing to do with whether
getImage
actually uses_ratingSelected
to generate its return value. The only connection betweengetImage
and_ratingSelected
from the data binding framework's point of view is the "propertyChange" event which they both claim to dispatch when their respective values have changed (even thoughgetImage
never actually dispatches it).