Flex - 发送一个参数到一个自定义的ItemRenderer? [英] Flex - Sending a parameter to a custom ItemRenderer?
问题描述
以下是我的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屋!