[英]Flex List selection and rendering problem
我的自定义列表有一些奇怪的问题。
我定义了需要显示员工列表的列表。 在我的自定义列表中,我想提供 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 属性时,我得到了正确的 object 和索引。
更重要的是,在关键的第一次出现时,当我将鼠标悬停在应该选择的项目上时,它会在我推出后保持选中状态(就像她应该的那样)。
随后的出现按预期进行。
我试图对我的问题给出“塑料”的描述,所以如果我提供的信息很少,请原谅。 我只是不明白问题是什么。 有任何想法吗?
最后,我发现了我的错误。
因为我的自定义列表在父组件的表单中,所以我创建 function 以在弹出窗口出现和绑定发生之前重置所有表单元素。 在该代码中,我输入了myCustomList.selectedItem=null
,当我删除该行时,一切都按预期工作。
不过,我不确定早期行为的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.