Flex 3:隐藏由转发器创建的元素
我有一个中继器,它创建一个名为“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实现您想要的最简单的方法就是使用数据绑定,就像您对“oneDay”值所做的那样。
[编辑以更加清晰]
要更改块的可见性,您需要设置 showBlocks 的值,如下所示:
或
The easiest way to achieve what you want is just to use databinding, same as you did for the "oneDay" value.
[Edit for additional clarity]
To change the visibility of the blocks, you need to set the value of showBlocks, like so:
or
这是我解决它的方法......由于每次创建块时都会声明“thisBlock”的变量名,因此所有信息都存储在数组中。学习完这一点后,我能够在按下显示/隐藏按钮时调用的函数中创建一个 for every 循环... for every 循环如下所示:
希望将来可以帮助其他人。
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:
Hope that can help somebody else out in the future.