private List<DateTime> dates;
private BindingList<DateTime> bDates;
private BindingSource dSource;
private DataTable dataTable = new DataTable();
public Form1() {
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) {
dates = new List<DateTime>();
dtpDate.Format = DateTimePickerFormat.Custom;
dtpDate.CustomFormat = "dd/MM/yyyy";
dtpTime.Format = DateTimePickerFormat.Custom;
dtpTime.CustomFormat = "hh:mm";
dtpTime.ShowUpDown = true;
dataTable.Columns.Add("Date", typeof(DateTime));
}
private void button1_Click(object sender, EventArgs e) {
DateTime input = dtpDate.Value.Date + dtpTime.Value.TimeOfDay;
MessageBox.Show(input.ToString()); //This shows the date correctly
dates.Add(input);
bDates = new BindingList<DateTime>(dates);
dSource = new BindingSource(bDates, null);
grid.DataSource = dSource;
grid.Columns[0].DefaultCellStyle.Format = "dd/MM/yyyy HH:mm";
// using datatable on second grid
dataTable.Rows.Add(input);
grid2.DataSource = dataTable;
grid2.Columns[0].DefaultCellStyle.Format = "dd/MM/yyyy hh:mm:ss tt";
}
例如,我有一个 const filterData = apiData.filter(data => {
return this.shouldDisplayItem(
data,
[this.state.searchValue],
this.state.filterKeyValue
);
}).filter(i => i.vid),
x = 0,
y = apiData.map(i => i.vid).indexOf(markerId);
A[x] = A.splice(y, 1, A[x])[0];
。首先,我要过滤大于2的值,然后通过索引号交换7和8。
首先在原始项目中,我正在做一些过滤,而不是在第二个过滤中,我交换了两个数组对象 我们可以一次过滤两次相同的数组吗?
答案 0 :(得分:1)
答案 1 :(得分:1)
您可以使用reduce()简单完成
所以在reduce函数中,我首先检查value > 2
条件。
value === 7
或value===8
是否与它们匹配,我将根据需要更改值。否则,我将直接推入输出数组。 value > 2
失败,我不会在输出数组中推送该值。
let arr = [0,1,2,3,4,5,6,7,8,9];
let op = arr.reduce((op,cur)=>{
if(cur>2){
if( cur ===7)op.push(8);
else if(cur === 8) op .push(7);
else op.push(cur);
}
return op;
},[])
console.log(op);