首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >itemRenderer in DataGrid

itemRenderer in DataGrid
EN

Stack Overflow用户
提问于 2012-02-19 19:25:48
回答 1查看 570关注 0票数 0

我的DataGrid中有一个DataGrid,它将根据DataGrid中大约8个不同节点的值来显示coloredBoxes (就像一个颜色键)。我“以为”我想出了解决方案,当你第一次启动应用程序时--应该显示do的彩色框和不显示do的彩色框--不要。但是当你滚动dataGrid时,它们都会改变。我尝试过几种不同的方法,一个定制的MXML组件,动作脚本,这两者都是,你可以给它命名,它总是做同样的事情。请有人看看这段代码,让我知道我做错了什么吗?

MXML:

代码语言:javascript
复制
<mx:DataGrid width="100%" height="100%" dataProvider="{gridData}"
             horizontalGridLines="true" horizontalGridLineColor="#666666">
    <mx:columns>
        <mx:DataGridColumn headerText="Publication title" dataField="pubTitle" showDataTips="true" dataTipField="dateEssentials"/>
        <mx:DataGridColumn headerText="Primary function" dataField="functionPrimary" width="150"/>
        <mx:DataGridColumn headerText="Lead writer" dataField="writerLead" width="150"/>
        <mx:DataGridColumn headerText="Primary channel" dataField="primaryChannel" width="150"/>
        <mx:DataGridColumn headerText="Primary date" dataField="primaryDate" width="100"
                           labelFunction="dgDateFormatter" sortCompareFunction="dgDateSorter"/>
        <mx:DataGridColumn dataField="dateEssentials" itemRenderer="scripts.DGImageRenderer"
                           width="150" resizable="false"/>
    </mx:columns>
</mx:DataGrid>

渲染者:

代码语言:javascript
复制
import mx.events.FlexEvent;
        override public function set data(value:Object):void {
            if (value != null) {
                super.data = value;
                trace(data.pubTitle);
                if (data.dateEyhpNews != null){
                    EyhpNews.visible = true;
                    trace("EYHP NEWS = " + data.dateEyhpNews);
                }
                if (data.dateEyhpSpotlight != null){
                    EyhpSpotlight.visible = true;
                    trace("EYHP SPOTLIGHT = " + data.dateEyhpSpotlight);
                }
                if (data.dateGsChs != null){
                    gsChs.visible = true;
                    trace("GS CHS = " + data.dateGsChs);
                }
                if (data.dateItsCHS != null){
                    itsChs.visible = true;
                    trace("ITS CHS = " + data.dateItsCHS);
                }
                if (data.dateProcChs != null){
                    procChs.visible = true;
                    trace("PROC CHS = " + data.dateProcChs);
                }
                if (data.dateEssentials != null){
                    essentials.visible = true;
                    trace("ESSENTIALS = " + data.dateEssentials);
                }
                if (data.dateEmail != null){
                    email.visible = true;
                    trace("EMAIL = " + data.dateEmail);
                }
                if (data.dateOther1 != null){
                    other1.visible = true;
                    trace("OTHER 1 = " + data.dateOther1);
                }
                if (data.dateOther2 != null){
                    other2.visible = true;
                    trace("OTHER 2 = " + data.pubTitle);
                }
                if (data.dateOther3 != null){
                    other3.visible = true;
                    trace("OTHER 3 = " + data.pubTitle);
                }
                trace(data.pubTitle);
            }
            dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE));
        }

<s:HGroup width="100%" height="100%" verticalAlign="middle" paddingLeft="5" paddingRight="5" >
    <mx:Box id="EyhpNews" visible="false" backgroundColor="0x0000FF" width="8" height="8" toolTip="EYHP News" />
    <mx:Box id="EyhpSpotlight" visible="false" backgroundColor="0xCC3300" width="8" height="8" toolTip="EYHP Spotlight" />
    <mx:Box id="gsChs" visible="false" backgroundColor="0x006699" width="8" height="8" toolTip="Global Services CHS" />
    <mx:Box id="itsChs" visible="false" backgroundColor="0xCC6600" width="8" height="8" toolTip="IT Services CHS" />
    <mx:Box id="procChs" visible="false" backgroundColor="0x993399" width="8" height="8" toolTip="Procurement CHS" />
    <mx:Box id="essentials" visible="false" backgroundColor="0x009933" width="8" height="8" toolTip="Essentials" />
    <mx:Box id="email" visible="false" backgroundColor="0xFF6666" width="8" height="8" toolTip="Email" />
    <mx:Box id="other1" visible="false" backgroundColor="0xFF6666" width="8" height="8" toolTip="Other 1" />
    <mx:Box id="other2" visible="false" backgroundColor="0xFF6666" width="8" height="8" toolTip="Other 2" />
    <mx:Box id="other3" visible="false" backgroundColor="0xFF6666" width="8" height="8" toolTip="Other 3" />
</s:HGroup>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-02-19 20:18:19

我认为当您滚动时,数据网格可能是重用项目呈现器。当它确实改变了项目呈现器的数据值时,它已经有了一些可见的框,并且使其他新的框可见。所以,你应该做的是确保旧的盒子不再可见。

例如,您可以这样做:

代码语言:javascript
复制
EyhpNews.visible = data.dateEyhpNews != null;
EyhpSpotlight.visible = data.dateEyhpSpotlight != null;
// ...
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9352420

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档