gpt4 book ai didi

apache-flex - flex, AdvancedDataGrid, 自定义 itemrenderer

转载 作者:行者123 更新时间:2023-12-01 02:51:57 25 4
gpt4 key购买 nike

当涉及到 flex itemrenderers 时,我似乎缺少一些关键概念,特别是当它适用于 AdvancedDataGrid 时。我正在做很多其他人正在尝试做的事情:根据行中的数据更改字段的 bg 颜色。我的问题似乎是在访问数据字段?基本上,当这个加载时,什么都没有出现。如果我从渲染器中删除我尝试访问字段数据的部分,它可以工作,但有点违背目的。

这是我所拥有的:

<mx:AdvancedDataGrid width="100%" height="100%" 
id="topAccountsGrid"
borderStyle="solid" dropShadowEnabled="true" treeColumn="{list_name}" editable="false" selectionMode="singleRow"
dragEnabled="true" dropEnabled="true" dragMoveEnabled="true" dragDrop="topAccountsGrid_dragDropHandler(event)"
doubleClickEnabled="true" itemDoubleClick="topAccountsGrid_itemDoubleClickHandler(event)"
sort="topAccountsGrid_sortHandler(event)" backgroundColor="#ffffff">
<mx:dataProvider>
<mx:HierarchicalData source="{filteredList}"
childrenField="children" />
</mx:dataProvider>
<mx:columns>
<mx:AdvancedDataGridColumn id="colRank" headerText="Rank" dataField="Rank__c" width="60">
<mx:itemRenderer>
<fx:Component>
<mx:HBox paddingLeft="2">
<s:Label id="tempLabel" text="{data.Rank__c}" />
<fx:Script>
<![CDATA[
override public function set data(value:Object) : void{
super.data = value;
if(data.Health__c == 0){
setStyle("backgroundColor",0xFF5050);
} else if(data.Health__c == 50){
setStyle("backgroundColor",0xFFFF99);
} else if(data.Health__c == 100){
setStyle("backgroundColor",0x66FF66);
}
}
]]>
</fx:Script>
</mx:HBox>
</fx:Component>
</mx:itemRenderer>
</mx:AdvancedDataGridColumn>
<mx:AdvancedDataGridColumn id="list_name" headerText="Name" dataField="Name" />
<mx:AdvancedDataGridColumn id="colPrevRank" headerText="Previous Rank" dataField="Previous_Rank__c" />
<mx:AdvancedDataGridColumn id="colType" headerText="Type" dataField="Type" />
<mx:AdvancedDataGridColumn id="colContacts" headerText="# Contacts" dataField="Contacts__c" />
<mx:AdvancedDataGridColumn id="colDeals" headerText="# Deals" dataField="Deals__c" />
</mx:columns>
</mx:AdvancedDataGrid>

最佳答案

过去我在使用 HierarchicalData 时遇到过类似的问题。 .我绕过它的方法是使用 AdvancedDataGridRendererProvider .

这是一些示例代码:

<mx:AdvancedDataGrid width="100%" height="100%" 
id="topAccountsGrid"
backgroundColor="#ffffff">
<mx:dataProvider>
<mx:HierarchicalData source="{filteredList}"
childrenField="children" />
</mx:dataProvider>
<mx:columns>
<mx:AdvancedDataGridColumn id="colRank" headerText="Rank" dataField="Rank__c" width="60" />
<mx:AdvancedDataGridColumn id="list_name" headerText="Name" dataField="Name" />
<mx:AdvancedDataGridColumn id="colPrevRank" headerText="Previous Rank" dataField="Previous_Rank__c" />
<mx:AdvancedDataGridColumn id="colType" headerText="Type" dataField="Type" />
<mx:AdvancedDataGridColumn id="colContacts" headerText="# Contacts" dataField="Contacts__c" />
<mx:AdvancedDataGridColumn id="colDeals" headerText="# Deals" dataField="Deals__c" />
</mx:columns>
<mx:rendererProviders>
<mx:AdvancedDataGridRendererProvider column="{colRank}" depth="1" dataField="Rank__c" renderer="AdvancedDataGridRankCRenderer" />
</mx:rendererProviders>
</mx:AdvancedDataGrid>

和 AdvancedDataGridRendererProvider:
<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
backgroundColor="{SetBackgroundColor(data)}"
paddingLeft="2" paddingRight="2" paddingTop="2"
horizontalScrollPolicy="off"
verticalScrollPolicy="off"
height="22">
<fx:Script>
<![CDATA[
[Bindable] private var bgColor:uint = 0xD6E5FF;

private function SetBackgroundColor(obj:Object):uint
{
var returnColor:uint = 0xFF5050;

if (obj["Rank__c"] != null)
{
switch (obj["Rank__c"].toString().toUpperCase())
{
case "0":
returnColor = 0xFF5050;
break;
case "50":
returnColor = 0xFFFF99;
break;
case "100":
returnColor = 0x66FF66;
break;
default:
returnColor = 0xFF5050;
break;
}
}

return returnColor;
}

override public function set data(value:Object):void
{
super.data = value;
rankLabel.text = value["Rank__c"].toString();
validateDisplayList();
}
]]>
</fx:Script>
<mx:Label id="rankLabel" />
</mx:HBox>

关于apache-flex - flex, AdvancedDataGrid, 自定义 itemrenderer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4623242/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com