0

如何停止将数据行附加到我的数据网格?我在状态之间切换。每次我回到 update_dg_form 状态时,都会将额外的 networkInfo 行添加到数据网格中。

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>  
4

1 回答 1

0

您可以在使用插入新信息之前从 networkInfo 中删除所有元素networkInfo.removeAll();

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>  
于 2012-10-15T09:12:06.920 回答