[英]C# How to add <list>string into Listview
如果你總是得到相同數量的列,那么你可以使用下面的代碼。
就像,你總是得到 5 列。
TCP
0.0.0.0:135
0.0.0.0:0
聽力
1028
import React from 'react'; import ReactDOM from 'react-dom'; import 'antd/dist/antd.css'; import './index.css'; import { Table } 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.keys(data).map(function(key) { if (counter == 0) { newData.splice(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( <Table dataSource={newData}> <Column title="Protocol" dataIndex="Protocol" key="Protocol" /> <Column title="Address1" dataIndex="Address1" key="Address1" /> <Column title="Address2" dataIndex="Address2" key="Address2" /> <Column title="Etat" dataIndex="Etat" key="Etat" /> <Column title="ProcNa" dataIndex="ProcNa" key="ProcNa" /> </Table>, document.getElementById('container') );
// Cheack to see if the number of items in the list in divisible by 5
if (validElements.Count % 5 != 0)
{
//keep adding items until the reminder is 0
while (validElements.Count % 5 != 0) {
validElements.Add("na");
}
}
// adding the items to the listview
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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.