从 ItemRenderer 获取变量到主应用程序
我有一个以 TextInput 作为项目渲染器的列表。我想获取在 TextInput 中输入的值(形成 TextInputItemRenderer)并将其传递给主应用程序以执行一些检查(在 textInput 上点击 Enter 后 - 请参阅下面的代码)。
我知道我们可以通过调度事件来完成此操作,但我仍然不明白如何将变量从 ItemRenderer 传递到主应用程序。
请帮助。
谢谢
<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
autoDrawBackground="true" xmlns:components="components.*" width="100%"
>
<s:layout>
<s:HorizontalLayout/>
</s:layout>
<fx:Script>
<![CDATA[
override public function set data( value:Object ) : void {
super.data = value;
}
protected function myTextInput_enterHandler(event:FlexEvent):void
{
trace(myTextInput.text);
What Next??
}
]]>
</fx:Script>
<components:ClearableTextInput text="{data.label}" id="myTextInput" enter="myTextInput_enterHandler(event)"/>
</s:ItemRenderer>
I have a List with TextInput as item renderer. I want to get the value entered in the TextInput (form the TextInputItemRenderer) and pass it the main application to do some checks(upon tapping enter on the textInput -- see code below).
I know that we can do it thru dispatching event but I still don't understand how to pass a variable from the ItemRenderer to the main app.
Help Pls.
Thanks
<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
autoDrawBackground="true" xmlns:components="components.*" width="100%"
>
<s:layout>
<s:HorizontalLayout/>
</s:layout>
<fx:Script>
<![CDATA[
override public function set data( value:Object ) : void {
super.data = value;
}
protected function myTextInput_enterHandler(event:FlexEvent):void
{
trace(myTextInput.text);
What Next??
}
]]>
</fx:Script>
<components:ClearableTextInput text="{data.label}" id="myTextInput" enter="myTextInput_enterHandler(event)"/>
</s:ItemRenderer>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定我是否正确地回答了你的问题,但这有帮助吗?
http://www.ajibanda.blogspot.com /2011/02/change-currentstate-of-main-and.html
i'm not sure if I got your question correctly but would this help?
http://www.ajibanda.blogspot.com/2011/02/changing-currentstate-of-main-and.html
我认为你可以向后做,而不是尝试从 MainApp 访问 itemRenderer。请遵循以下两种解决方案之一:
在 itemRenderer 中,将您稍后要检查的值分配给 MainApp 上的公共全局变量。限制是您只能在 MainApp 上检查它,而不能在其他任何地方(其他 itemRenderer、组件、模块等)
使用 EvenBus 将值放入全局容器。例如,在 AppUtils 中创建一个静态 eventBus 实例。在 itemRenderer 中,AppUtils.eventBus.dispatch() 是一个事件,每次值更改时都会附加该值。然后再次使用 AppUtils.eventBus 来 addEventListener() 检索值并检查您想要的位置。 Google AS3Commons for EventBus。
Instead of trying to access from MainApp to itemRenderer, i think you can do backward. Follow one of two solutions below:
In itemRenderer, assign value you want to check later to a public global variable on the MainApp. The limitation is you then only enable to check it on MainApp, not any where esle (other itemRenderer, component, module etc.)
Use EvenBus to put the value to a global container. Create a static eventBus instance in AppUtils, for example. In itemRenderer, AppUtils.eventBus.dispatch() an event with the value attached to it each time the value changed. And then use AppUtils.eventBus again to addEventListener() to retrieve the value and check wherever you want. Google AS3Commons for EventBus.