在 Flex 中的 itemrenderer 上获取工具提示正确刷新时出现问题

发布于 2024-10-06 04:00:36 字数 1448 浏览 4 评论 0原文

我遇到以下问题。

我有一个 ArrayCollection,它充当tilelist(称为favoriteLinksList)的数据提供者,

我使用一个名为FavoriteItem的itemRenderer作为tilelist的itemRenderer。这个FavoriteItem看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
 width="280" height="163"
 horizontalAlign="center"
 paddingLeft="5" paddingRight="5" paddingTop="0" paddingBottom="0" xmlns:ns1="*">

 <mx:Canvas width="100%" height="100%">
  <mx:Image
   id="thumbnail"
   width="178" height="115"
   source="{data.thumbnail}"
   toolTip = "{data.tooltip}" x="46" y="10"/>

  <mx:Text
   id="title"
   text="{data.tileListTitle}" 
   width="254"
   toolTip="{data.tooltip}" x="10" y="133"/>
 </mx:Canvas>

</mx:VBox>

正如你所看到的,其中两个项目的工具提示取自data.tooltip

这工作正常。

问题是当工具提示发生变化时刷新它。

ArrayCollection 中的对象(Object 类型)每个都有一个名为 tooltip 的属性(显然,因为这是 itemRenderer 从中获取信息的地方)。

当我将此属性更改为其新值时,itemRenderer 的工具提示不会更改以反映这一点。

我尝试通过从单击图块列表中的项目之一触发的事件中获取 itemRenderer 来手动设置它,但没有成功。

示例:

event.itemRenderer.title.toolTip = event.currentTarget.selectedItem.tooltip;

更新工具提示后,但这会出现编译错误: 通过静态类型 mx.controls.listClasses:IListItemRenderer 的引用访问可能未定义的属性标题。

我还尝试对 favoriteLinksList 数组集合执行刷新(),但这给出了混合结果。工具提示已正确更新,但图块列表中的一个项目(第一个)丢失了!这似乎是 Flex 的一个错误。数据提供程序在刷新之前和之后具有相同数量的元素,如果我单击图块列表中的第一个元素,则不会发生这种情况。

非常感谢所有帮助。

I'm having the following problem.

I have an ArrayCollection that's acting as the data provider for a tilelist (called favoriteLinksList)

I use an itemRenderer called FavoriteItem as the tilelist's itemRenderer. This FavoriteItem looks like this:

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
 width="280" height="163"
 horizontalAlign="center"
 paddingLeft="5" paddingRight="5" paddingTop="0" paddingBottom="0" xmlns:ns1="*">

 <mx:Canvas width="100%" height="100%">
  <mx:Image
   id="thumbnail"
   width="178" height="115"
   source="{data.thumbnail}"
   toolTip = "{data.tooltip}" x="46" y="10"/>

  <mx:Text
   id="title"
   text="{data.tileListTitle}" 
   width="254"
   toolTip="{data.tooltip}" x="10" y="133"/>
 </mx:Canvas>

</mx:VBox>

As you can see, the tooltips for the two items in it are taken from data.tooltip

This works fine.

The problem is refreshing the tooltip when it has changed.

The objects (of type Object) in the ArrayCollection each have a property called tooltip (obviously since that's where the itemRenderer is getting its info from).

When I change this property to its new value, the tooltip of the itemRenderer doesn't change to reflect this.

I tried to set it manually by getting the itemRenderer from the event that is triggered upon clicking one of the items in the tilelist but without success.

Example:

event.itemRenderer.title.toolTip = event.currentTarget.selectedItem.tooltip;

after having updated the tooltip but this gives a compilation error:
Access of possibly undefined property title through a reference with static type mx.controls.listClasses:IListItemRenderer.

I also tried performing a refresh() on the favoriteLinksList array collection but this gave mixed results. The tooltip was updated correctly but one of the items (the first one) in the tilelist went missing! This seems to be a Flex bug. The data provider has the same number of elements before and after the refresh and this doesn't happen if I click on the first element in the tilelist.

All help is greatly appreciated.

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

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

发布评论

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

评论(2

对你而言 2024-10-13 04:00:36

找到了解决我的问题的方法。

favoriteLinksList 是可绑定的,并设置为tileList 的dataProvider。但是,对各个对象的更改不会传播到 itemRenderer。

我认为 favoriteLinksList 数组集合本身必须发生变化。

正如我的问题中提到的,我已经尝试使用favoriteLinksList.refresh(),但这使得tileList中的第一个元素消失(尽管它似乎仍然在数组集合中)。 Flex 中可能存在错误吗?

不管怎样,发现解决这个问题的方法是执行以下操作:

favoriteLinksList.setItemAt(favoriteObject, favoriteLinksList.getItemIndex(favoriteObject));

本质上,我将索引 X 处的项目设置为其自身,因此实际上没有执行任何操作,但这足以让 itemRenderer 刷新 itemRenderer 的数据。

Found a solution to my problem.

The favoriteLinksList is bindable and set as the dataProvider of the tileList. However, changes to the individual objects were not being propagated to the itemRenderer.

I thought that there must a change to the favoriteLinksList Array Collection itself.

As mentioned in my question, I already tried using favoriteLinksList.refresh() but this made the first element in the tileList vanish (though it still seemed to be in the Array Collection). A possible bug in Flex perhaps?

Anyway, discovered that a way around this was to perform the following:

favoriteLinksList.setItemAt(favoriteObject, favoriteLinksList.getItemIndex(favoriteObject));

Essentially, I'm setting the item at index X to itself so not actually doing anything but this is enough for the itemRenderer to refresh the data for the itemRenderer.

沧桑㈠ 2024-10-13 04:00:36

我会做两件事

  1. 该对象实际上是可绑定的并且正在发生更改并到达项目渲染器

  2. 可能的解决方案=>重写项目渲染器中 data 属性的 setter,不要忘记调用 super.data = value

-

override public function set data(value:Object):void
{
 super.data = value;
 title.toolTip = data.tooltip;
}

在这一行中设置断点,当数据更改时您应该能够到达它。

I would go about doing 2 things

  1. that the object is actually bindable and the change is happening and getting to the item renderer

  2. possible solution => override the setter for the data property in the item renderer, do not forget to call super.data = value

-

override public function set data(value:Object):void
{
 super.data = value;
 title.toolTip = data.tooltip;
}

stand with a breakpoint in this row, you should be getting to it when the data changes.

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