我有List<string>,它包含了cmd中netstat命令的決議輸出,你看到的串列是這樣的:
TCP
0.0.0.0: 135
0.0.0.0:0
監聽
1028
TCP
0.0.0:445
0.0.0.0:0
監聽
4
TCP
0.0.0:5040
0.0.0.0:0
監聽
1328
TCP
0.0.0:5357
0.0.0.0:0
監聽
4:4
我想把每5行添加到串列視圖中的一行,以便它們與它們的列協議等相匹配,我怎樣才能做到這一點?
uj5u.com熱心網友回復:
如果你總是得到相同數量的列,那么你可以使用下面的代碼。
比如,你總是得到5列。
TCP
TCP
0.0.0.0:135
0.0.0.0:135
0.0.0.0:0
0.0.0.0:0
LISTENING
1028
import React from 'react'/span>; import ReactDOM from 'react-dom'; import 'antd/dist/antd.css'; import './index.css'; 匯入 { 表 } from 'antd'; const { Column } = Table; const data = [ 'TCP'。 '0.0.0.0:135'。 '0.0.0.0:0'。 'LISTENING', '1028', 'TCP'。 '0.0.0.0:445'。 '0.0.0.0:0'。 'LISTENING', '4', 'TCP'。 '0.0.0.0:5040'。 '0.0.0.0:0'。 'LISTENING', '1328', 'TCP'。 '0.0.0.0:5357'。 '0.0.0.0:0'。 'LISTENING', '4'. ]; let newData = []; let counter = 0; let index = 0; Object.key(data).map(function(key) { if (counter == 0) { newData.splicice(index, 0, { ...newData[index], Protocol: data[key] })。 counter = 1; } else if (counter == 1) { newData.splice(index, 0, { ...newData[index], Address1: data[key] })。) newData.splice(index 1, 1) 。 counter = 2; } else if (counter == 2) { newData.splice(index, 0, { ...newData[index], Address2: data[key] })。 newData.splice(index 1, 1) 。 counter = 3; } else if (counter == 3) { newData.splice(index, 0, { ...newData[index], Etat: data[key] })。 newData.splice(index 1, 1) 。 counter = 4; } else if (counter == 4) { newData.splice(index, 0, { ...newData[index], ProcNa: data[key] })。 newData.splice(index 1, 1) 。 counter = 0; index = index 1; } }); ReactDOM.render( <表 dataSource={newData}> <列 title="協議" dataIndex="協議" key="協議" /> <列 title="Address1" dataIndex="Address1" key="Address1" /> <列 title="Address2" dataIndex="Address2" key="Address2" /> <列 title="Etat" dataIndex="Etat" key="Etat" /> <Column title="ProcNa" dataIndex="ProcNa" key="ProcNa" /> </Table>。 document.getElementById('container') );
uj5u.com熱心網友回復:
// Cheack to see if the number of items in the list in divisible by 5
if (validElements.Count % 5 != 0)
{
//繼續添加專案,直到提醒者為0。
while (validElements.Count % 5 != 0) {
validElements.Add("na")。
}
}
//將專案添加到串列視圖中。
for (var i = 0; i < validElements.Count; i =5)
{
ListViewItem lvi = new ListViewItem(validElements[i])。
lvi.SubItems.Add(validElements[i 1] )。)
lvi.SubItems.Add(validElements[i 2])。
lvi.SubItems.Add(validElements[i 3])。
lvi.SubItems.Add(validElements[i 4])。
listView1.Items.Add(lvi)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/315706.html
標籤:

