Flex 3:隐藏由转发器创建的元素

发布于 2024-11-04 01:20:26 字数 1328 浏览 5 评论 0原文

我有一个中继器,它创建一个名为“Block”的自定义组件。我需要这样做,以便当用户单击按钮时,转发器创建的所有块的可见字段都设置为 false(然后再次单击按钮时设置为 true)。

这是我现在拥有的一些代码:

<mx:Repeater id="indPositions" dataProvider="{projectPositions}" startingIndex="0">
        <components:block height="24"
            width="100%" id="thisBlock" visible="true" horizontalScrollPolicy="off"  
            oneDay="{oneDay}"
        />
    </mx:Repeater>

这是用户单击以显示/隐藏块的按钮:

<mx:Button id="showHideButton" label="Show Project" x="{addBlock.x + addBlock.width + 2}" click="showProjectSwitch();" />

这是函数 showProjectSwitch():

public function showProjectSwitch():void {
            if (showHideButton.label == "Hide Project")
            {   
                showHideButton.label = "Show Project";
                indPositions.visible = false;
                thisProject.height = 65;
            }
            else
            {   
                showHideButton.label = "Hide Project";
                indPositions.visible = true;
                thisProject.height = projectHeight ;
            }
        }

我尝试设置 projectRP.visible="true/false",但它不起作用:(

我也尝试在中继器周围包裹画布,但是当我这样做时......中继器只运行一次,尽管我有startingIndex =“0”和count =“16”。然后我删除了画布标签中继器运行了正确的次数

有人能帮我吗?

I have a repeater that creates a custom component named "Block." I need to make it so that when the user clicks a button, all of the blocks created by the repeater have their visible field set to false (and then true when the button is clicked again).

Here's some of the code I have right now:

<mx:Repeater id="indPositions" dataProvider="{projectPositions}" startingIndex="0">
        <components:block height="24"
            width="100%" id="thisBlock" visible="true" horizontalScrollPolicy="off"  
            oneDay="{oneDay}"
        />
    </mx:Repeater>

Here's the button the user will click to show/hide the blocks:

<mx:Button id="showHideButton" label="Show Project" x="{addBlock.x + addBlock.width + 2}" click="showProjectSwitch();" />

Here's the function showProjectSwitch():

public function showProjectSwitch():void {
            if (showHideButton.label == "Hide Project")
            {   
                showHideButton.label = "Show Project";
                indPositions.visible = false;
                thisProject.height = 65;
            }
            else
            {   
                showHideButton.label = "Hide Project";
                indPositions.visible = true;
                thisProject.height = projectHeight ;
            }
        }

I tried setting projectRP.visible="true/false", but it didn't work :(

I also tried wrapping a canvas around the repeater, but when I did that... the repeater only ran once despite the fact I have the startingIndex="0" and the count="16". I then removed the canvas tags and the repeater ran the correct number of times.

Anybody able to help me out?

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

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

发布评论

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

评论(2

柠檬色的秋千 2024-11-11 01:20:26

实现您想要的最简单的方法就是使用数据绑定,就像您对“oneDay”值所做的那样。

<mx:Repeater id="indPositions" dataProvider="{projectPositions}" startingIndex="0">
    <components:block height="24"
        width="100%" id="thisBlock" visible="true" horizontalScrollPolicy="off"  
        oneDay="{oneDay}"
        visible="{showBlocks}"
    />
</mx:Repeater>
<mx:Boolean id="showBlocks" />

[编辑以更加清晰]
要更改块的可见性,您需要设置 showBlocks 的值,如下所示:

showBlocks = true;

showBlocks = false;

The easiest way to achieve what you want is just to use databinding, same as you did for the "oneDay" value.

<mx:Repeater id="indPositions" dataProvider="{projectPositions}" startingIndex="0">
    <components:block height="24"
        width="100%" id="thisBlock" visible="true" horizontalScrollPolicy="off"  
        oneDay="{oneDay}"
        visible="{showBlocks}"
    />
</mx:Repeater>
<mx:Boolean id="showBlocks" />

[Edit for additional clarity]
To change the visibility of the blocks, you need to set the value of showBlocks, like so:

showBlocks = true;

or

showBlocks = false;
生生漫 2024-11-11 01:20:26

这是我解决它的方法......由于每次创建块时都会声明“thisBlock”的变量名,因此所有信息都存储在数组中。学习完这一点后,我能够在按下显示/隐藏按钮时调用的函数中创建一个 for every 循环... for every 循环如下所示:

for (var I:int = 0; i < dataprovidername.length; i++)
    thisBlock[i].visible = true/flase;

希望将来可以帮助其他人。

Here's how i solved it... since the variable name of "thisBlock" is declared every time a block is made, all that information gets stored in an array. After learning this, i was able to create a for each loop in a function that was called when the show/hide button was pressed... the for each loop goes something like this:

for (var I:int = 0; i < dataprovidername.length; i++)
    thisBlock[i].visible = true/flase;

Hope that can help somebody else out in the future.

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