flex datagrid不会追加行

时间:2012-10-12 11:13:58

标签: actionscript-3 flex4.5

如何停止追加到我的数据网格的数据行?我在州之间切换。每次我返回update_dg_form状态时,其他networkInfo行都会添加到datagrid。

private function update_dg(event:MouseEvent):void
{           
    var ntf:Vector.<NetworkInterface> = NetworkInfo.networkInfo.findInterfaces();
    for each (var interfaceObj:NetworkInterface in ntf)
    {
        networkInfo.addItem({"dg_display_name" : interfaceObj.displayName, "dg_mac_address" : interfaceObj.hardwareAddress});
    }
        currentState = 'update_dg_form';                    
}

<mx:DataGrid id="network_adapter" includeIn="update_dg_form" x="55" y="280" width="516" height="111" dataProvider="{networkInfo}" selectedIndex="0">
    <mx:columns>
        <mx:DataGridColumn dataField="dg_display_name" headerText="Network Adapter"/>
        <mx:DataGridColumn dataField="dg_mac_address" headerText="MAC Address"/>
    </mx:columns>
</mx:DataGrid>  

1 个答案:

答案 0 :(得分:0)

您可以在使用networkInfo.removeAll();

插入新信息之前从networkInfo中删除所有元素
private function update_dg(event:MouseEvent):void {
    var ntf:Vector.<NetworkInterface> = NetworkInfo.networkInfo.findInterfaces();
    networkInfo.removeAll();
    for each (var interfaceObj:NetworkInterface in ntf) {
        networkInfo.addItem({"dg_display_name":interfaceObj.displayName, "dg_mac_address":interfaceObj.hardwareAddress});
    }
    currentState = 'update_dg_form';
}

<mx:DataGrid id="network_adapter" includeIn="update_dg_form" x="55" y="280" width="516" height="111" dataProvider="{networkInfo}" selectedIndex="0">
    <mx:columns>
        <mx:DataGridColumn dataField="dg_display_name" headerText="Network Adapter"/>
        <mx:DataGridColumn dataField="dg_mac_address" headerText="MAC Address"/>
    </mx:columns>
</mx:DataGrid>