Flex:名为“result”的 dataProvider 变量制造麻烦。为什么?
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
private var result : ArrayCollection = new ArrayCollection([1,2,3]);
]]>
</mx:Script>
<mx:List dataProvider="{result}"/>
</mx:Application>
我有这个代码。问题是:如果我的 dataProvider 变量名为“result”,那么在运行的应用程序中,列表包含唯一的元素“[object Binding]”。如果我将“结果”重命名为其他任何内容(例如“res”),列表将按预期显示 - “1”、“2”、“3”。为什么?
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
private var result : ArrayCollection = new ArrayCollection([1,2,3]);
]]>
</mx:Script>
<mx:List dataProvider="{result}"/>
</mx:Application>
I have this code. The problem is: if my variable for dataProvider is named "result", then in the running application the List contains the only element "[object Binding]". By if I rename "result" for anything else (for example "res"), the List is displayed as expected - "1", "2", "3". Why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简短回答:这是 FLEX 中的一个错误。我已经报告了。
这很奇怪...如果我们使用 Spark List 控件,它甚至无法编译。它告诉我们它无法将
Array
转换为IList
。result
显然是某个地方的变量,但是在哪里呢?因此,我研究了使用 -keep- generated-actionscript=true 编译器标志生成的代码。
在 ViewName-generate.as 文件中,您会发现一个有趣的方法:
这是 Binding 对象生成
result
变量的地方。我们可以在绑定对象中看到有一个返回
(result)
的函数。在任何其他情况下,这将是类似(results)
的内容。但是,在本例中,它返回Binding
对象的本地数组。这就是this.result
起作用的原因。它正在脱离本地范围!所以,这显然是一个错误。我已将其提交给 Adobe,如下所示: https://bugs.adobe.com/jira/浏览/FB-29870
Short answer: THIS IS A BUG IN FLEX. I HAVE REPORTED IT.
This is odd... If we use the Spark List control, it won't even compile. It tells us that it can't convert
Array
toIList
.result
is obviously a variable some place, but where?So I looked into the code that is generated using the -keep-generated-actionscript=true compiler flag.
Inside the ViewName-generate.as file, you will find an interesting method:
This is where the Binding objects are making into your
result
variable.We can see in the binding object that there is a function that returns
(result)
. In any other case, this would be something else like(results)
. BUT, in this case, it is returning the local array ofBinding
objects. That is whythis.result
works. It is pulling out of the local scope!So, this is obviously a bug. I have submitted it to Adobe as such: https://bugs.adobe.com/jira/browse/FB-29870
我只是在 Flex 中尝试列表和数组。我尝试了 this.result,效果很好。我认为结果可能是保留的。
抢
I am just experimenting with Lists and Arrays in Flex. I tried
this.result
, it worked fine. I assume the result is maybe reserved.Rob