Flex:将变量传递给自定义组件时,应用程序会感到困惑 [英] Flex: application is confused when passing variables to custom component

查看:29
本文介绍了Flex:将变量传递给自定义组件时,应用程序会感到困惑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Flex 的新手,我缺少关于构建 Flex 应用程序的一些非常基本的东西——我已经实现了一个自定义组件 MyReportGrid 并扩展了 GridColumnMyColumn.我试图概述下面的应用程序代码.

值得注意的是,OfficeItems 类被 MyItems 类和 MyColumn(它扩展了 GridColumn) 包含一个 customPath 变量,用于访问类内部的变量 penpencilstaplerOfficeItems.

我相信这就是为什么手动排序(通过单击数据网格中的列)仅适用于对应于 zipCodestateCode 而不是 的列的原因penpencil订书机.

此外,当我尝试对 zipCodestateCode 使用简单的 labelFunction 时,它总是可以正常工作,但是为 pen 实现了 labelFunction,pencilstapler 永远不起作用.从不工作"我的意思是 labelFunction 被正确调用,并且它执行它的必需任务,因为 labelFunction 接收正确的对象并实际返回正确格式的字符串,但此返回值从未显示在数据网格中(我是假设 customPath 变量会使 labelFunction 混淆返回的 String 映射到哪个变量).

我认为这些都是相同的问题,因为 MyColumncustomPath 方面会混淆应用程序.知道如何修复排序和/或 labelFunction 吗?提前感谢您耐心阅读这篇(长篇)帖子.

课程是:

package com.supportClasses{公共类 OfficeItems {公共 var 笔:*;公共 var 铅笔:*;公共 var 订书机:*;}}

包 com.models{导入 com.supportClasses.OfficeItems;[可绑定]公共类 MyItems 扩展模型 {公共函数 myItems() {极好的();}public var office:OfficeItems;公共变量邮政编码:int;公共变量状态代码:字符串;}}

数据网格如下所示:

<预><代码>...<components:MyReportGrid id="myGrid" dataProvider="{_myData}"...><组件:列><fx:数组><supportClasses:MyColumn customPath="office" dataField="pen".../><supportClasses:MyColumn customPath="office" dataField="pencil".../><supportClasses:MyColumn customPath="office" dataField="stapler".../><supportClasses:MyColumn dataField="zipCode".../><supportClasses:MyColumn dataField="stateCode".../>...

其中 _myData 有一个 MyItems 类(注意:customPath 特性在没有时被 MyColumn 忽略出现在这里,例如 zipCodestateCode).MyColumn 是:

package com.components.supportClasses {导入 spark.components.gridClasses.GridColumn;公共类 MyColumn 扩展了 GridColumn{public var customPath:String="";...公共函数 MyColumn(headerText:String="header" customPath:String="", dataField:String="data", ...) {this.headerText=headerText;this.customPath=customPath;this.dataField=dataField;...}}}

而 MyReportGrid 是:

package com.models {<?xml version="1.0" encoding="utf-8"?><s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"xmlns:s="library://ns.adobe.com/flex/spark"xmlns:mx="library://ns.adobe.com/flex/mx"宽度=400"高度=300">导入 com.components.myClasses.MyColumn;导入 com.itemRenderers.myItemRenderer;导入 mx.collections.ArrayCollection;导入 mx.collections.ArrayList;导入 mx.collections.ListCollectionView;导入 spark.components.gridClasses.GridColumn;...<s:DataGrid width="100%" .../></s:组>}

labelFunction 是:

私有函数 redFormat(item:Object, column:MyColumn):String {var formatResult:String = "red "+item.office.pen;返回格式结果;//返回红色 Bic15938"(例如)}

调用自:

<supportClasses:MyColumn customPath="office" dataField="pen" labelFunction="redFormat".../>

解决方案

这只是一个猜测,但是否可以像向 OfficeItems 类添加toString"函数那样?(我会使用评论,但仍在努力获得声誉.)

I'm new to Flex and I'm missing something very basic about architecting a Flex application -- I've implemented a custom component MyReportGrid and extended GridColumn with MyColumn. I've tried to outline the application code below.

The interesting thing to notice is that class OfficeItems is used by class MyItems, and the MyColumn (which extends GridColumn) includes a customPath variable that is used to access variables pen, pencil, and stapler inside class OfficeItems.

I believe that is the reason why manually sorting (by clicking on the columns in the datagrid) only works for columns corresponding to zipCode and stateCode and NOT pen, pencil, and stapler.

Also, when I try to use a simple labelFunction for zipCode or stateCode it always works fine, but implementing a labelFunction for pen, pencil, or stapler never works. By "never works" I mean that the labelFunction is called correctly, and it performs it's required task in that the labelFunction receives the correct object and actually returns the correct formatted String, but this returned value is never displayed in the datagrid (I'm assuming the customPath variable confuses the labelFunction as to which variable the returned String maps to).

I think these are both the same issue in that the customPath aspect of the MyColumn confuses the application. Any idea how to fix the sorting and/or labelFunction? Thanks in advance for your patience in reading this (long) posting.

The classes are:

package com.supportClasses  
{
    public class OfficeItems {
    public var pen:*;
    public var pencil:*;
    public var stapler:*;
    }
}

and

package com.models
{
    import com.supportClasses.OfficeItems;
    [Bindable]
    public class MyItems extends Model {
        public function myItems() {
            super();
        }
        public var office:OfficeItems;
        public var zipCode:int;
        public var stateCode:String;
    }
}

The data grid looks like:

...
<components:MyReportGrid id="myGrid" dataProvider="{_myData}"...>
    <components:columns>
        <fx:Array>
            <supportClasses:MyColumn customPath="office" dataField="pen"... />
            <supportClasses:MyColumn customPath="office" dataField="pencil"... />
            <supportClasses:MyColumn customPath="office" dataField="stapler"... />
            <supportClasses:MyColumn dataField="zipCode"... />
            <supportClasses:MyColumn dataField="stateCode"... />
            ...

where _myData has a class of MyItems (note: the customPath feature is ignored by MyColumn when not present here, such as for zipCode and stateCode). MyColumn is:

package com.components.supportClasses {
    import spark.components.gridClasses.GridColumn;
    public class MyColumn extends GridColumn
    {
        public var customPath:String="";
        ...
        public function MyColumn(headerText:String="header" customPath:String="", dataField:String="data", ...) {
           this.headerText=headerText;
           this.customPath=customPath;
           this.dataField=dataField;
           ...
        }
    }
}

and MyReportGrid is:

package com.models {
    <?xml version="1.0" encoding="utf-8"?>
    <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"    
         xmlns:s="library://ns.adobe.com/flex/spark" 
         xmlns:mx="library://ns.adobe.com/flex/mx"
         width="400" height="300">
       import com.components.myClasses.MyColumn;
       import com.itemRenderers.myItemRenderer;
       import mx.collections.ArrayCollection;
       import mx.collections.ArrayList;
       import mx.collections.ListCollectionView;
       import spark.components.gridClasses.GridColumn;
       ...
       <s:DataGrid width="100%" ... />
    </s:Group>
}

the labelFunction is:

private function redFormat(item:Object, column:MyColumn):String {
   var formatResult:String = "red "+item.office.pen;
   return formatResult; // returns "red Bic15938" (for example)
}

as called from:

<supportClasses:MyColumn customPath="office" dataField="pen" labelFunction="redFormat"... />

解决方案

This is just a guess, but could it be something like adding a "toString" function to the OfficeItems class? (I would be using comments, but still working on getting reputation.)

这篇关于Flex:将变量传递给自定义组件时,应用程序会感到困惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆