从主应用程序调用 Spark 列表中 itemRenderer 内部函数的简单方法
我有一个包含列表的主应用程序,使用自定义 itemRenderer 来显示数据。
我希望能够从主应用程序调用 itemRenderer 内部的函数。
运行应用程序时,我们有一个包含三个人的列表和一个按钮。我想从主应用程序中调用列表中所选项目的 itemRenderer 内的函数 myItemRendererFunction() 。
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.FlexEvent;
[Bindable]
private var _dp:ArrayCollection = new ArrayCollection([
{firstname: "Bob", lastname: "Smith"},
{firstname: "Gerard", lastname: "Pearson"},
{firstname: "Peter", lastname: "Bell"}
]);
protected function checkAll():void
{
// Here I want to call the "myItemRendererFunction()" function
// inside the itemRenderer of the selected row
}
]]>
</fx:Script>
<s:layout>
<s:VerticalLayout paddingBottom="10" paddingLeft="10" paddingRight="10" paddingTop="10"/>
</s:layout>
<s:List id="myList" width="100%" height="100%" dataProvider="{_dp}" itemRenderer="renderers.FriendDisplayRenderer"/>
<s:Button label="Check All for selected item" click="checkAll()"/>
</s:WindowedApplication>
现在,我的 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">
<fx:Script>
<![CDATA[
public function myItemRendererFunction():void
{
chk_1.selected = true;
chk_2.selected = true;
chk_3.selected = true;
}
]]>
</fx:Script>
<s:layout>
<s:HorizontalLayout paddingBottom="10" paddingLeft="10" paddingRight="10" paddingTop="10"/>
</s:layout>
<s:Label text="{data.firstname} {data.lastname}" width="150"/>
<s:CheckBox id="chk_1" label="Likes hockey"/>
<s:CheckBox id="chk_2" label="Likes baseball"/>
<s:CheckBox id="chk_3" label="Likes football"/>
</s:ItemRenderer>
感谢您的帮助!!!!
I have a main application that contains a list, using a custom itemRenderer to display data.
I would like to be able to call a function, inside the itemRenderer, from the main application.
When running the app, we have a list with three persons, and a button. I want to call the function myItemRendererFunction() inside the itemRenderer, of the selected item in the list, all this, from the main app.
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.FlexEvent;
[Bindable]
private var _dp:ArrayCollection = new ArrayCollection([
{firstname: "Bob", lastname: "Smith"},
{firstname: "Gerard", lastname: "Pearson"},
{firstname: "Peter", lastname: "Bell"}
]);
protected function checkAll():void
{
// Here I want to call the "myItemRendererFunction()" function
// inside the itemRenderer of the selected row
}
]]>
</fx:Script>
<s:layout>
<s:VerticalLayout paddingBottom="10" paddingLeft="10" paddingRight="10" paddingTop="10"/>
</s:layout>
<s:List id="myList" width="100%" height="100%" dataProvider="{_dp}" itemRenderer="renderers.FriendDisplayRenderer"/>
<s:Button label="Check All for selected item" click="checkAll()"/>
</s:WindowedApplication>
And now, my 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">
<fx:Script>
<![CDATA[
public function myItemRendererFunction():void
{
chk_1.selected = true;
chk_2.selected = true;
chk_3.selected = true;
}
]]>
</fx:Script>
<s:layout>
<s:HorizontalLayout paddingBottom="10" paddingLeft="10" paddingRight="10" paddingTop="10"/>
</s:layout>
<s:Label text="{data.firstname} {data.lastname}" width="150"/>
<s:CheckBox id="chk_1" label="Likes hockey"/>
<s:CheckBox id="chk_2" label="Likes baseball"/>
<s:CheckBox id="chk_3" label="Likes football"/>
</s:ItemRenderer>
Thanks for the help !!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
渲染器将根据提供的数据进行渲染。
因此,您真正要做的就是更改数据并重新渲染。
Renderers will render depending on the data that is provided.
So all you really have to do is change the data and re-render.