Flex - 将参数发送到自定义 ItemRenderer? [英] Flex - Sending a parameter to a custom ItemRenderer?
问题描述
我想要完成的工作是让我的 Flex Datagrid 中的财务数据进行颜色编码——如果它是积极的,则为绿色;如果是负数则为红色.如果我想要着色的列是 dataProvider 的一部分,这将相当简单.相反,我根据属于 dataProvider 的另外两列计算它.这仍然相当简单,因为我可以在 ItemRenderer 中再次计算它,但计算的另一部分是基于 textBox 的值.所以,我认为我需要能够做的是将 textBox 的值发送到自定义 ItemRenderer,但由于该值存储在主 MXML 应用程序中,我不知道如何访问它.将其作为参数发送似乎是最好的方式,但也许还有另一种方式.
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.
这是我的 ItemRenderer 的当前代码:
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 不存在)
(data.AvailableFunding doesn't exist)
那么有谁知道我将如何完成这项工作?
So does anyone know how I would go about accomplishing this?
推荐答案
您可能需要查看 ClassFactory 来自 Flex API:
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;
上面的代码假设ProductRenderer"有一个名为showProductImage"的公共属性,该属性将被设置为true".
The above code assumed that "ProductRenderer" has a public property called "showProductImage" which will be set with a value of "true."
这篇关于Flex - 将参数发送到自定义 ItemRenderer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!