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

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

问题描述

我是新来的Flex和我想的东西很基本的架构有关Flex应用程序 - 我已经实现了一个自定义组件 MyReportGrid 和扩展的GridColumn 根据MyColumn 。我试着概括如下应用code。

有趣的事情要注意的是,类 OfficeItems 由类 MyItems 根据MyColumn (延伸的GridColumn )包括用于访问的 customPath 变量变量铅笔订书机内部类 OfficeItems

我想这也是为什么手动排序(通过点击列在DataGrid)的原因只能对应于拉链code柱状态code 和NOT 铅笔订书机

此外,当我尝试用一​​个简单的labelFunction为拉链code 状态code 它总是工作正常,但实施的labelFunction为铅笔订书机永远不会奏效。通过永远的作品我的意思是的labelFunction正确调用,并执行它的任务需要,该​​的labelFunction接收到正确的目标和实际返回正确的格式化的字符串,但该返回值永远不会显示在数据网格(我假设 customPath 变量混淆了labelFunction哪个变量返回的字符串映射到)。

我觉得这些都是在根据MyColumn 混淆了应用程序的 customPath 方面同样的问题。任何想法如何解决排序和/或的labelFunction?在此先感谢您在阅读本(长)发布的耐心。

的类是:

 包com.supportClasses
{
    公共类OfficeItems {
    公共变种笔:*;
    公共变种铅笔:*;
    公共变种订书机:*;
    }
}
 

 包com.models
{
    进口com.supportClasses.OfficeItems;
    [可绑定]
    公共类MyItems扩展模式{
        公共职能myItems(){
            超();
        }
        公共变种办公室:OfficeItems;
        公共变种拉链code:INT;
        公共变种状态code:字符串;
    }
}
 

数据网格是这样的:

  ...
<组件:MyReportGrid ID =myGrid的dataProvider ={_ myData的}...>
    <组件:列>
        < FX:阵列>
            < supportClasses:根据MyColumn customPath =办公室的dataField =笔... />
            < supportClasses:根据MyColumn customPath =办公室的dataField =铅笔... />
            < supportClasses:根据MyColumn customPath =办公室的dataField =订书机... />
            < supportClasses:根据MyColumn的dataField =拉链code... />
            < supportClasses:根据MyColumn的dataField =状态code... />
            ...
 

其中, _myData 有一个类 MyItems (注意:在 customPath 功能通过根据MyColumn 的时候没有present这里,如拉链code 状态code )。 根据MyColumn 是:

 包com.components.supportClasses {
    进口spark.components.gridClasses.GridColumn;
    公共类根据MyColumn扩展的GridColumn
    {
        公共变种customPath:字符串=;
        ...
        公共职能根据MyColumn(HEADERTEXT:字符串=头customPath:字符串=,的dataField:字符串=数据,...){
           this.headerText = HEADERTEXT;
           this.customPath = customPath;
           this.dataField =的dataField;
           ...
        }
    }
}
 

和MyReportGrid是:

 包com.models {
    < XML版本=1.0编码=UTF-8&GT?;
    < S:组的xmlns:FX =htt​​p://ns.adobe.com/mxml/2009
         XMLNS:S =库://ns.adobe.com/flex/spark
         的xmlns:MX =库://ns.adobe.com/flex/mx
         WIDTH =400HEIGHT =300>
       进口com.components.myClasses.MyColumn;
       进口com.itemRenderers.myItemRenderer;
       进口mx.collections.ArrayCollection;
       进口mx.collections.ArrayList;
       进口mx.collections.ListCollectionView;
       进口spark.components.gridClasses.GridColumn;
       ...
       &所述氏:数据网格宽度=100%... />
    < / S:组>
}
 

中的labelFunction是:

 私有函数redFormat(项目:对象,列:根据MyColumn):字符串{
   VAR formatResult:字符串=红色+ item.office.pen;
   返回formatResult; //返回红Bic15938(例如)
}
 

为所谓的:

 < supportClasses:根据MyColumn customPath =办公室的dataField =笔的labelFunction =redFormat... />
 

解决方案

这只是一个猜测,但会不会像增加一个的toString功能的OfficeItems类? (我将使用评论,但仍在努力获得的声誉。)

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.)

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

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