📜  如何在打字稿代码示例中的数组中添加新索引

📅  最后修改于: 2022-03-11 14:48:14.494000             🧑  作者: Mango

代码示例2
let currentDate = formatDate(new Date(), 'MM/dd/yyyy', 'en');
    let objPurchare=new PurchaseOrderLineItems();
    objPurchare.Id=obj.Id;
    objPurchare.ItemNo=obj.ItemNo+1;
    objPurchare.MultiReleaseNo=obj.MultiReleaseNo+1;
    objPurchare.DateCreated=obj.DateCreated;
    objPurchare.Partno=obj.Partno;
    objPurchare.OnHold=obj.OnHold;
    objPurchare.Description=obj.Description;
    objPurchare.Supplier=obj.Supplier;
    objPurchare.LastPurchase=obj.LastPurchase;
    objPurchare.OrderQty=0;
    objPurchare.Demand=obj.Demand;
    objPurchare.AvgUsage=parseFloat(obj.AvgUsage).toFixed(4);
    objPurchare.LeadTime=obj.LeadTime;
    objPurchare.OnHand=obj.OnHand;
    objPurchare.PromiseDate= this.datePipe.transform(obj.PromiseDate, 'yyyy-MM-dd'),
    objPurchare.Notes=obj.Notes;
    objPurchare.Checked=false;
    objPurchare.ApplyRedClass=formatDate(obj.DateCreated, 'MM/dd/yyyy', 'en') < currentDate ? true : false;
    objPurchare.BuyerId= obj.BuyerId;
    objPurchare.MultiRelease=0;  
    objPurchare.Addbtn= true;
    objPurchare.IsMultiRelease=false;

    const insert = (arr, index, newItem) => [
      // part of the array before the specified index
      ...arr.slice(0, index),
      // inserted item
      newItem,
      // part of the array after the specified index
      ...arr.slice(index)
    ]   
    this.reOrderQueueList[i].MultiReleaseLineItems=insert(this.reOrderQueueList[i].MultiReleaseLineItems, j+1, objPurchare)

    let counter=1;
    for (let x = 0; x < this.reOrderQueueList[i].MultiReleaseLineItems.length; x++) {
      this.reOrderQueueList[i].MultiReleaseLineItems[x].ItemNo=counter;
      this.reOrderQueueList[i].MultiReleaseLineItems[x].MultiReleaseNo=counter;
      counter++
    }