使用 itemrenderer 显示 Flex 进度条列表

发布于 2024-09-25 01:21:03 字数 691 浏览 6 评论 0原文

我想创建一个进度条列表并相应地更新该列表。 我在数组中有组数据,

 <mx:Array id="arr">
        <mx:Object label="Group One" min="0" max="200" currentValue="60" />
        <mx:Object label="Group Two" min="0" max="300" currentValue="50" />
 </mx:Array>

数组对象中的值表示组的名称、最小值、最大值和当前值 对于组(用于进度条)。

我使用带有“mx.controls.ProgressBar”的列表作为 itemRenderer 现在

<mx:List width="100%" dataProvider="{arr}"
        itemRenderer="mx.controls.ProgressBar"/>

我需要的是每当数组“arr”的 currentValue 字段发生变化时我想更新进度条“progress”值到currentValue(其中进度条的最小值和最大值存储在数组“arr”中)

我该如何做同样的事情。

谢谢大家

I want to create a list of progress bars and update the list accordingly.
I have group data in an Array as

 <mx:Array id="arr">
        <mx:Object label="Group One" min="0" max="200" currentValue="60" />
        <mx:Object label="Group Two" min="0" max="300" currentValue="50" />
 </mx:Array>

The values in the array object indicate name of group,minimum,maximum and current value
for the group (to be used in progressbar).

I used the list with "mx.controls.ProgressBar" as itemRenderer as

<mx:List width="100%" dataProvider="{arr}"
        itemRenderer="mx.controls.ProgressBar"/>

Now what I need is whenever currentValue field of Array "arr" changes i want to update the progressbar "progress" value to currentValue (where min and maximum value of progressbar are stored in Array "arr")

How can i do the same.

Thanks all

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

谷夏 2024-10-02 01:21:03

我猜你的进度条没有显示任何内容,因为所有这些都是错误的。项目渲染器是一个类,它通过函数set data(value:Object):void从数据提供者获取单个项目。要获取 ProgressBar 内的值,您可以对其进行子类化,添加数据函数(getter 和 setter)并从那里设置属性 - 该类将是项目渲染器。

接下来,不保证 itemRenderers 始终被实例化。 List 根据需要显示它们来创建它们,并将未使用的存储在池中。这意味着您无法与特定列表项交谈 - 池中的任何项目都可以发挥其作用(获取其数据)。要更改进度,您需要更新数据提供程序,然后重新设置。

I guess your ProgressBars are displaying nothing, because all that is wrong. Item renderer is a class which is getting single item from data provider via function set data(value:Object):void. To get values inside ProgressBar, you can subclass it, add data function (getter and setter) and set properties from there - this class will be item renderer.

Next, itemRenderers aren't guaranteed to be instantiated at all times. List creates them as they needed to be shown, and stores unused in a pool. This means you cannot talk to particular list item - any item from pool could play its role (getting its data). To change progress, you need to update data provider, and set it again.

猛虎独行 2024-10-02 01:21:03

诀窍是将进度条的模式设置为手动,因为您不会自动侦听下载数据的任何进度。您想要设置一个值,以便进度条可以自行更新,因此手动是可行的方法。此外,请检查一下:

<s:Application minHeight="600" minWidth="955" xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:s="library://ns.adobe.com/flex/spark">
<s:layout>
    <s:HorizontalLayout/>
</s:layout>
<fx:Declarations>
    <s:ArrayCollection id="arr">
        <fx:Object label="Group One" currentValue="20" max="200" min="0"/>
        <fx:Object label="Group Two" currentValue="50" max="300" min="0"/>
    </s:ArrayCollection>
</fx:Declarations>
<fx:Script>
    <![CDATA[
        private function updateArr():void {
            arr.getItemAt(0).currentValue = ns.value;
        }
    ]]>
</fx:Script>
<s:List dataProvider="{arr}"  itemRenderer="ProgressBarWithCurrentValue"/>
<s:NumericStepper id="ns" maximum="200" minimum="0" stepSize="10" value="20" change="updateArr()"/></s:Application>

这是 itemrenderer 代码,您将看到该模式为手动:

<s:ItemRenderer autoDrawBackground="true" xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:s="library://ns.adobe.com/flex/spark">
<fx:Script>
    <![CDATA[
        private function updateCurrentValue():void {
            pb.setProgress(data.currentValue, data.max);
        }
    ]]>
</fx:Script>
<mx:ProgressBar id="pb" maximum="{data.max}" minimum="{data.min}" mode="manual" updateComplete="updateCurrentValue()"/></s:ItemRenderer>

当您简单地将 itemrenderer 设置为进度条时,它会自动尝试查找数据源,但在您的情况下,您将自己提供和更新。因此,您可能需要一个项目渲染器来执行一些操作。

The trick is to set the mode of progressbar to manual since you are not automatically listening to any progress of a downloaded data. You want to set a value so progress bar could update itself so manual is the way to go. Moreover, check this out :

<s:Application minHeight="600" minWidth="955" xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:s="library://ns.adobe.com/flex/spark">
<s:layout>
    <s:HorizontalLayout/>
</s:layout>
<fx:Declarations>
    <s:ArrayCollection id="arr">
        <fx:Object label="Group One" currentValue="20" max="200" min="0"/>
        <fx:Object label="Group Two" currentValue="50" max="300" min="0"/>
    </s:ArrayCollection>
</fx:Declarations>
<fx:Script>
    <![CDATA[
        private function updateArr():void {
            arr.getItemAt(0).currentValue = ns.value;
        }
    ]]>
</fx:Script>
<s:List dataProvider="{arr}"  itemRenderer="ProgressBarWithCurrentValue"/>
<s:NumericStepper id="ns" maximum="200" minimum="0" stepSize="10" value="20" change="updateArr()"/></s:Application>

Here is the itemrenderer code, you'll see the mode as manual :

<s:ItemRenderer autoDrawBackground="true" xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:s="library://ns.adobe.com/flex/spark">
<fx:Script>
    <![CDATA[
        private function updateCurrentValue():void {
            pb.setProgress(data.currentValue, data.max);
        }
    ]]>
</fx:Script>
<mx:ProgressBar id="pb" maximum="{data.max}" minimum="{data.min}" mode="manual" updateComplete="updateCurrentValue()"/></s:ItemRenderer>

When you simply set itemrenderer to a progressbar, it automatically tries to find a datasource but in your case you'll be feeding and updating yourself. So, you'll need an itemrenderer where you do some operations maybe.

虐人心 2024-10-02 01:21:03

大家好
感谢您的回答..
经过更多谷歌搜索后,我发现了与我需要的类似的东西
http://www.flex-blog.com/progressbar-in-datagrid- example/

与上面的 2 个答案非常相似.. by @kubarium 和 @alxx ..
1. 使用 ItemRenderer 在 DataGrid 中显示 ProgressBar。
2. 为 DataGrid 创建 DataProvider。
3. 创建一个动作来启动ProgressBar
4. 确保 ArrayCollection 在每次进展时都会更新
进度条。

hi all
thanks for the answers..
After googling thr more I found something similar to what i need here
http://www.flex-blog.com/progressbar-in-datagrid-example/

Pretty similar to the 2 answers above.. by @kubarium and by @alxx ..
1. Use an ItemRenderer to show the ProgressBar inside the DataGrid .
2. Create a DataProvider for the DataGrid .
3. Create an action to start the ProgressBar
4. Make sure the ArrayCollection is updated on every progress of the
ProgressBar.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文