我在Flex中有一個DataGrid,其中一列是複選框,另一列是數值。單擊複選框時,數值應該更改,如果複選框未選中,則數值應爲0;如果選中該複選框,則數值應爲預定義的最小值。這裏是我的代碼有:Flex DataGrid:根據另一個值更改值?
<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>
數據的值更新(我可以看到它時,我關閉和打開對話框這是),但它並不在數據網格中即時更新。點擊複選框後,我怎樣才能使價值顯着改變?
謝謝,但這不是我需要設置的最小和最大值,它是實際值(data.antal)。它正在dataprovider中設置,但直到我重置數據網格的數據提供者時才顯示在數據網格中。 – Lizzan 2010-10-04 12:58:46
代碼仍然是它應該如何工作的基本概念。既然你實際上並沒有在代碼中的任何地方顯示'antal'值,我不確定你要更新的視覺樣片 – JeffryHouser 2010-10-04 13:05:15
'antal'值是數據網格第二列中顯示的值。這是我單擊複選框時不明顯更新的內容。 – Lizzan 2010-10-04 13:14:54