代码之家  ›  专栏  ›  技术社区  ›  Lizzan

flex-datagrid:根据另一个值更改值?

  •  2
  • Lizzan  · 技术社区  · 15 年前

    我在flex中有一个数据报,其中一列是复选框,另一列是数值。单击该复选框时,数值应更改,如果未选中该复选框,则改为0;如果选中该复选框,则改为预定义的最小值。这是我的代码:

    <mx:DataGrid x="0" y="45" width="272" height="525" dataProvider="{dp}" variableRowHeight="true" editable="true" id="equipmentDG" verticalAlign="middle">                
        <mx:columns>                    
    
            <mx:DataGridColumn headerText="" headerStyleName="gridheader" width="20" dataField="included" editorDataField="selected" rendererIsEditor="true">
                <mx:itemRenderer>
                    <fx:Component>
                        <mx:CheckBox click="handleClicks(event)">
                            <fx:Script>
                                <![CDATA[
                                public function handleClicks(event:MouseEvent):void
                                {
                                    data.included = !data.included;
    
                                    if(data.included && data.antal == 0)     
                                        data.antal = data.minNo; 
                                    else if(!data.included) 
                                        data.antal = 0;
                                }
                                ]]>
                            </fx:Script>
                        </mx:CheckBox>
                    </fx:Component>
                </mx:itemRenderer>
            </mx:DataGridColumn>
            <mx:DataGridColumn headerText="Antal" headerStyleName="gridheader" width="40" dataField="antal" editorDataField="value" editable="true">
                <mx:itemEditor>
                    <fx:Component>
    
                        <mx:NumericStepper stepSize="1" width="35" height="20"  focusOut="numericstepper1_changeHandler(event)">
                            <fx:Script>
                                <![CDATA[
                                import mx.events.NumericStepperEvent;
                                override public function set data(value:Object):void
                                {
                                    super.data = value;
    
                                    if (value && value.hasOwnProperty("minNo"))
                                        minimum = value.minNo;
    
                                    if (value && value.hasOwnProperty("maxNo"))
                                        maximum = value.maxNo;                                              
                                }
    
                                protected function numericstepper1_changeHandler(event:Event):void
                                {
                                    if(data.antal > 0)
                                        data.included = true;
                                    else
                                        data.included = false;
                                }
    
                                ]]>
                            </fx:Script>
    
                        </mx:NumericStepper>                                        
    
                    </fx:Component>
                </mx:itemEditor>
            </mx:DataGridColumn>
    
    
        </mx:columns>
    </mx:DataGrid>
    

    值在数据中更新(当我关闭并打开此对话框时可以看到),但它不会在数据网格中立即更新。单击复选框后,如何使值明显更改?

    3 回复  |  直到 15 年前
        1
  •  3
  •   JeffryHouser    15 年前

    private var _included : Boolean;
    public function get included():Boolean{
     return this._included;
    }
    
    public function set included(value:Boolean):void
     this._included = value;
     this.dispatchEvent(new Event('includedChanged');
    }
    

     <mx:DataGridColumn headerText="Antal" headerStyleName="gridheader" width="40" dataField="antal" editorDataField="value" editable="true">
      <mx:itemRenderer>
       <fx:Component>
       <mx:Label dataChange="onDataChange()" >
        <fx:Script>
         <![CDATA[
          public function onDataChange():void{
           thistext = data['Antal'];
           this.data.addEventListener('includedChanged',onIncludedChange);
          }
          public function onIncludedChange(e:Event):void{
           this.text = data['Antal'];
          }
         ]]>
        </fx:Script>
       </mx:Label>
      </fx:Component>
      </mx:itemRenderer>
      <mx:itemEditor>
       <fx:Component>
    
        <mx:NumericStepper stepSize="1" width="35" height="20"  focusOut="numericstepper1_changeHandler(event)">
         <fx:Script>
          <![CDATA[
           import mx.events.NumericStepperEvent;
           override public function set data(value:Object):void{
            super.data = value;
    
            if (value && value.hasOwnProperty("minNo"))
             minimum = value.minNo;
    
            if (value && value.hasOwnProperty("maxNo"))
              maximum = value.maxNo;                                              
            }
    
            protected function numericstepper1_changeHandler(event:Event):void
            {
             if(data.antal > 0)
              data.included = true;
             else
              data.included = false;
             }
    
             ]]>
            </fx:Script>
           </mx:NumericStepper>                                        
          </fx:Component>
         </mx:itemEditor>
        </mx:DataGridColumn>
    
        2
  •  1
  •   Maria Sakharova    15 年前

        3
  •  -1
  •   splash    15 年前

    dataProvider

    推荐文章