简体   繁体   English

在Flex的项目渲染器上获取正确刷新工具提示的问题

[英]Problem getting tooltip to refresh properly on an itemrenderer in Flex

I'm having the following problem. 我遇到以下问题。

I have an ArrayCollection that's acting as the data provider for a tilelist (called favoriteLinksList) 我有一个ArrayCollection充当tilelist(称为favoriteLinksList)的数据提供程序

I use an itemRenderer called FavoriteItem as the tilelist's itemRenderer. 我使用名为FavoriteItem的itemRenderer作为图块列表的itemRenderer。 This FavoriteItem looks like this: 这个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>

As you can see, the tooltips for the two items in it are taken from data.tooltip 如您所见,其中两项的工具提示来自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). ArrayCollection中的对象(类型为Object)每个都有一个称为工具提示的属性(显然,这是itemRenderer从中获取其信息的位置)。

When I change this property to its new value, the tooltip of the itemRenderer doesn't change to reflect this. 当我将此属性更改为其新值时,itemRenderer的工具提示不会更改以反映这一点。

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. 我试图通过从单击tilelist中的项目之一但未成功触发的事件中获取itemRenderer来手动设置它。

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. 更新工具提示后,但是会出现编译错误:通过静态类型为mx.controls.listClasses:IListItemRenderer的引用访问可能未定义的属性标题。

I also tried performing a refresh() on the favoriteLinksList array collection but this gave mixed results. 我还尝试在favouriteLinksList数组集合上执行refresh(),但这产生了混合结果。 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. 这似乎是Flex错误。 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. 数据提供者在刷新前后具有相同数量的元素,如果我单击tilelist中的第一个元素,则不会发生这种情况。

All help is greatly appreciated. 非常感谢所有帮助。

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 可能的解决方案=>覆盖项目渲染器中data属性的设置器,不要忘记调用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. 在该行中带有断点的地方,当数据更改时您应该到达断点。

Found a solution to my problem. 找到了解决我问题的方法。

The favoriteLinksList is bindable and set as the dataProvider of the tileList. favoriteLinksList是可绑定的,并设置为tileList的dataProvider。 However, changes to the individual objects were not being propagated to the itemRenderer. 但是,对单个对象的更改没有传播到itemRenderer。

I thought that there must a change to the favoriteLinksList Array Collection itself. 我认为必须对favoriteLinksList数组集合本身进行更改。

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). 正如我的问题中提到的那样,我已经尝试过使用favoriteLinksList.refresh(),但这使tileList中的第一个元素消失了(尽管它似乎仍然在Array Collection中)。 A possible bug in Flex perhaps? Flex中可能存在错误?

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. 本质上,我将索引X上的项目设置为其自身,因此实际上不做任何事情,但这足以使itemRenderer刷新itemRenderer的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM