【问题标题】:Flex: referencing all data in TileListFlex:引用 TileList 中的所有数据
【发布时间】:2009-09-03 09:17:37
【问题描述】:

我的 Flex 应用程序中有 2 个 TileList 组件。

1 tilelist 充满了数据,很像下面的 xml 示例:

<person name="Test">
<likes>Flex</likes>
<likes>PHP</likes>
</person>
<person name="test2">
<likes>HTML</likes>
<likes>CSS</likes>
</person>

该图块列表中显示的数据是名称。

我的第二个瓦片列表:

<items>
<preference>Flex</preference>
<preference>Flash</preference>
<preference>HTML</preference>
<preference>CSS</preference>
<preference>PHP</preference>
<preference>CMS</preference>
<preference>ASP</preference>
<preference>C</preference>
</items>

显示的数据是偏好。

用户可以点击第一个图块列表,然后应该在第二个图块列表中选择人们“喜欢”的项目(换句话说,它们会亮起)。

我的第一个图块列表上的点击事件

private function highlightPreferences(e:ListEvent):void{
trace(e.currentTarget);
//and now I'm stuck
}

有什么方法可以实现吗?

【问题讨论】:

  • 我厌倦了 tilelist 的有限功能,所以我创建了一个带有中继器组件的网格。我的答案可以在这里找到:stackoverflow.com/questions/1224393/... 更改中继器中组件的样式可以通过添加一个 ID 并循环遍历它来完成。

标签: apache-flex actionscript-3 air selection tilelist


【解决方案1】:

只需编写一个返回特定人的 selectedIndices 的函数。然后,像这样绑定第二个 TileList 的 selectedIndices:selectedIndices="{findLikes(firstList.selectedItem)}" 如果 firstList.selectedItem 更改,则绑定将触发。

哦,请不要使用中继器。列表可以做所有转发器可以做得更好的事情。

【讨论】:

  • 感谢您的回答,尽管我不喜欢 tilelist 解决方案。主要是因为 tilelist 有点受限(并且更难编码)。示例:您有一个包含 4 个项目的 tilelist,单击时每个项目都需要不同的背景颜色,并且可以选择多选。我想我不习惯使用 tilelist 来流畅地编写代码。
  • 是的,一开始肯定更难,但是掌握 flex 中的列表是我做过的最好的事情之一。问题是您必须开始将它们视为数据驱动的组件。因此,您的 dataprovider 中有一个属性,例如 selected,并让您的项目渲染器绑定到它以确定背景颜色。然后,您可以在数据被选中时更改所选属性,或使用绑定。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-02-15
  • 2011-01-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多