Flex - 发送一个参数到一个自定义的ItemRenderer? [英] Flex - Sending a parameter to a custom ItemRenderer?

查看:171
本文介绍了Flex - 发送一个参数到一个自定义的ItemRenderer?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图完成的任务是让我的Flex Datagrid中的财务数据进行颜色编码 - 如果是正数,则为绿色;红色,如果是负面的。如果我想着色的列是dataProvider的一部分,这将是相当简单的。相反,我正在计算它是基于dataProvider的一部分的其他两列。这仍然是相当简单的,因为我可以在ItemRenderer中再次计算它,但计算的另一部分是基于文本框的值。所以,我认为我需要做的是将textBox的值发送到自定义的ItemRenderer,但是由于该值存储在主MXML应用程序中,所以我不知道如何访问它。发送它作为参数似乎是最好的方式,但也许有另一种。



以下是我的ItemRenderer的当前代码:

  package {
import mx.controls.Label;
导入mx.controls.listClasses。*;

public class PriceLabel extends Label {
private const POSITIVE_COLOR:uint = 0x458B00 // Green
private const NEGATIVE_COLOR:uint = 0xFF0000; // Red

覆盖保护函数updateDisplayList(unscaledWidth:Number,unscaledHeight:Number):void {
super.updateDisplayList(unscaledWidth,unscaledHeight);

/ *根据商品价格设置字体颜色。 * /
setStyle(color,(data.AvailableFunding> = 0)?NEGATIVE_COLOR:POSITIVE_COLOR);




$(data.AvailableFunding不存在)那么有没有人知道我将如何去完成这个?

解决方案

您可能需要查看Flex中的 ClassFactory API:

这允许你设置一个原型的Object,任意的类型/值将被传递给项目渲染器。从示例:

  var productRenderer:ClassFactory = new ClassFactory(ProductRenderer); 
productRenderer.properties = {showProductImage:true};
myList.itemRenderer = productRenderer;上面的代码假定ProductRenderer有一个名为showProductImage的公共属性,它将被设置为值为true。

What I am trying to accomplish to to get financial data in my Flex Datagrid to be color-coded--green if it's positive; red if it's negative. This would be fairly straightforward if the column I want colored was part of the dataProvider. Instead, I am calculating it based on two other columns that are part of the dataProvider. That would still be fairly straightforward because I could just calculate it again in the ItemRenderer, but another part of the calculation is based on the value of a textBox. So, what I think I need to be able to do is send the value of the textBox to the custom ItemRenderer, but since that value is stored in the main MXML Application, I don't know how to access it. Sending it as a parameter seems like the best way, but perhaps there's another.

Here is the current code for my ItemRenderer:

package {
import mx.controls.Label;
import mx.controls.listClasses.*;

public class PriceLabel extends Label {
    private const POSITIVE_COLOR:uint = 0x458B00 // Green
    private const NEGATIVE_COLOR:uint = 0xFF0000; // Red 

    override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
        super.updateDisplayList(unscaledWidth, unscaledHeight);

        /* Set the font color based on the item price. */
        setStyle("color", (data.AvailableFunding >= 0) ? NEGATIVE_COLOR : POSITIVE_COLOR);
    }
}

(data.AvailableFunding doesn't exist)

So does anyone know how I would go about accomplishing this?

解决方案

You may want to look into ClassFactory from the Flex APIs:

This allows you to set a prototype Object with arbitrary types / values each of which will be passed to the item renderer. From the sample:

var productRenderer:ClassFactory = new ClassFactory(ProductRenderer);
productRenderer.properties = { showProductImage: true };
myList.itemRenderer = productRenderer;

The above code assumed that "ProductRenderer" has a public property called "showProductImage" which will be set with a value of "true."

这篇关于Flex - 发送一个参数到一个自定义的ItemRenderer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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