Flex - Sending a parameter to a custom ItemRenderer?

后端 未结 10 1342
悲哀的现实
悲哀的现实 2020-12-24 07:37

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 straight

相关标签:
10条回答
  • 2020-12-24 07:43

    I like to override the set data function of the item renderer to change the renderer when the data provider changes as shown here

    When you override the function you could cast the object to your object to make the availableFunding property available.

    To access the text box you could try creating a public property and binding the property to the text box in the mxml file:

    public var textVar:String;
    
                <mx:itemRenderer>
                    <mx:Component>
                        <customrenderer textVar="{txtBox.text}" />
                    </mx:Component>
                </mx:itemRenderer>
    
    0 讨论(0)
  • 2020-12-24 07:44

    You use outerDocument property. Please see the fx:Component reference.

    0 讨论(0)
  • 2020-12-24 07:45

    See this example:

    itemRenderer="{UIUtils.createRenderer(TextBox,{iconSrc:IconRepository.linechart,headerColor:0xB7D034,subHeaderColor:0xE3007F,textColor:0x75757D})}"
                                       
    
    0 讨论(0)
  • 2020-12-24 07:50

    Nice ClassFactory Example here

    0 讨论(0)
  • 2020-12-24 07:51

    Ah, so I knew about outerDocument but not parentDocument. I was able to just use parentDocument.*whatever I want from the main App and I can access it as long as it's public.

    Example:

    setStyle("color", (parentDocument.availableFunding >= 0) ? POSITIVE_COLOR : NEGATIVE_COLOR);
    

    Sweet! :)

    0 讨论(0)
  • 2020-12-24 07:55

    There's another technique, which, while it initially feels a little hacky is perhaps less cumbersome and cleaner in actual use.

    It involves the little-observed fact that an event dispatch is, of course, synchronous and the event object can be treated as a value object populated by any event handler.

    i.e. the ItemRenderer can do something like:

      ...
      var questionEvt:DynamicEvent = new DynamicEvent('answerMeThis', true, true);
      if (dispatchEvent(questionEvt))
      {
          if (questionEvent.answer == "some value")
          ....
    

    With a corresponding handler somewhere up the view hierarchy above the renderer that has a listener on the event and does something like:

    function handleAnswerMeThis(event:DynamicEvent):void
    {
         event.answer = "another value";
         event.dataHelper = new DataHelperThingy();
    }
    

    etc.

    It need not be a DynamicEvent - I'm just using that for lazy illustrative purposes.

    0 讨论(0)
提交回复
热议问题