如何解决Flex列表选择和呈现问题
| 我的自定义列表存在一些奇怪的问题。 我定义了需要显示员工列表的列表。在我的自定义列表中,我想提供selectedId属性,以便选择(突出显示)具有具体ID的员工。 列表是根据[http://blog.flexdevelopers.com/2010/02/flex-examples-binding-value-to-combobox.html]创建的。 这是我的自定义列表的代码...<mx:List ....>
<mx:Script>
<![CDATA[
private var _selectedId:int;
public function get selectedId():int
{
//...
}
public function set selectedId(id:int):void
{
_selectedId=id;
invalidateProperties();
invalidateDisplayList();
}
override protected function commitProperties():void
{
super.commitProperties();
if(dataProvider!=null)
setSelectedId();
}
protected function setSelectedId():void
{
var subordinates:ArrayCollection=dataProvider as ArrayCollection;
var subordinate:EmployeeSimpleDTO=null;
for(var i:int=0;i<subordinates.length;i++)
{
var sub:EmployeeSimpleDTO=(subordinates.getItemAt(i))as EmployeeSimpleDTO;
if(sub.employeeId==_selectedId)
{
subordinate=sub;
_selectedId=sub.employeeId;
break;
}
}
selectedItem=subordinate;
}
override protected function collectionChangeHandler(event:Event):void
{
super.collectionChangeHandler(event);
invalidateProperties();
invalidateDisplayList();
}]]>
<mx:Script>
<mx:itemRenderer>
<mx:Component>
<view:SubordinatesListItem employeeId = \"{data.employeeId}\"
employeeName = \"{data.employeeName}\"
employeeSurname = \"{data.employeeSurname}\"
employeeUsername = \"{data.employeeUsername}\"/>
</mx:Component>
</mx:itemRenderer>
</mx:List>
编辑
这是我的项目渲染器的代码
<mx:HBox xmlns:mx=\"http://www.adobe.com/2006/mxml\" width=\"100%\">
<mx:Script>
<![CDATA[
[Embed(source=\"/assets/employeeIcon.png\")]
[Bindable]
private var employeeIcon:Class;
[Embed(source=\"/assets/infoIcon.png\")]
[Bindable]
private var infoIcon:Class;
//-----------------------------
// private var declarations
//-----------------------------
private var _employeeId:int;
public function get employeeId():int
{
return _employeeId;
}
public function set employeeId(id:int):void
{
_employeeId=id;
}
private var _employeeName:String;
[Bindable]
public function get employeeName():String
{
return _employeeName;
}
public function set employeeName(name:String):void
{
_employeeName=name;
}
private var _employeeSurname:String;
[Bindable]
public function get employeeSurname():String
{
return _employeeSurname;
}
public function set employeeSurname(surname:String):void
{
_employeeSurname=surname;
}
private var _employeeUsername:String;
[Bindable]
public function get employeeUsername():String
{
return _employeeUsername;
}
public function set employeeUsername(username:String):void
{
_employeeUsername=username;
}
private function dispatchShowSubordinateDetails():void
{
dispatchEvent(new Event(\"showSubordinateDetails\",true));
}
]]>
</mx:Script>
<mx:Metadata>
[Event(name=\"showSubordinateDetails\",type=\"flash.events.Event\")]
</mx:Metadata>
<mx:Image source=\"{employeeIcon}\" scaleX=\"0.35\" scaleY=\"0.35\"/>
<mx:Label text=\"{employeeName} {employeeSurname}\"/>
<mx:Label text=\" [{employeeUsername}]\" color=\"#8D8D8D\"/>
<mx:Spacer width=\"100%\"/>
<mx:LinkButton icon=\"{infoIcon}\" click=\"dispatchShowSubordinateDetails()\" width=\"30\"/>
</mx:HBox>
在我的代码中,我在自定义列表的selectedId属性上绑定了一些值(列表位于弹出窗口-TitleWindow内)。
现在,只有在我的自定义列表的第一个显示中,ID才与selectedId相同的雇员在列表中没有被直观地选中(着色)。当我直观地说时,我的意思是当我接受自定义列表的selectedItem或selectedIndex属性时,将获得正确的对象和索引。
更重要的是,在关键的第一次出现时,当我将鼠标悬停在应选择的项目上时,在我展开后它仍保持选中状态(如她应该的那样)。
随后的演出表现如预期。
我试图给出我的问题的“塑料”描述,所以请给我一点点信息。我只是不明白问题是什么。有任何想法吗?
解决方法
最后,我发现了我的错误。
因为我的自定义列表在父组件的表单内,所以我创建了在弹出窗口显示和绑定发生之前重置所有表单元素的函数。在该代码中,我输入
myCustomList.selectedItem=null
,然后删除该行,一切按预期进行。
不过,我不确定早期行为的原因。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。