2015-10-07 107 views
1

我試圖刪除基於值的多維數組內的元素,它是StockNo從基於值的多維數組中刪除元素

我的數組是這樣的:

Array[2] 
0: Object 
     StockNo: "1" 
     InvoiceNo: "1234" 
     MaterialName: "MaterialName1" 
     PONo: "1234" 
     PRNo: "2124" 
     Project: "ProjectName" 
     Qty: "1" 
     Remarks: "Test" 
     Supplier: "SupplierName" 
     TotalAmount: "23" 
     Type: "2" 
     Unit: "23" 

    1: Object 
     StockNo: "2"  
     InvoiceNo: "1234" 
     MaterialName: "MaterialName2" 
     PONo: "1234" 
     PRNo: "2124" 
     Project: "ProjectName2" 
     Qty: "1" 
     Remarks: "Test" 
     Supplier: "SupplierName" 
     TotalAmount: "23" 
     Type: "2" 
     Unit: "23" 

的邏輯是:

var StockNo = 1; 
while(//find StockNo in the Multi-dimentional array){ 
    if(//StockNo found){ 
     //remove element 
    } 
} 

我怎樣才能在jQuery的做到這一點?

回答

1

KYLE GWAPO

嘗試使用濾鏡陣列:

var arrayOrig = [{ StockNo: "1", 
           InvoiceNo: "1234", 
           MaterialName: "MaterialName1", 
           PONo: "1234", 
           PRNo: "2124", 
           Project: "ProjectName", 
           Qty: "1", 
           Remarks: "Test", 
           Supplier: "SupplierName", 
           TotalAmount: "23", 
           Type: "2", 
           Unit: "23"}, 
          {StockNo: "2",  
           InvoiceNo: "1234", 
           MaterialName: "MaterialName2", 
           PONo: "1234", 
           PRNo: "2124", 
           Project: "ProjectName2", 
           Qty: "1", 
           Remarks: "Test", 
           Supplier: "SupplierName", 
           TotalAmount: "23", 
           Type: "2", 
           Unit: "23"}] 
      console.log(arrayOrig); 

      var filter_array = arrayOrig 
        .filter(function (el) { 
          alert(el.StockNo); 
          return el.StockNo !== "1"; 
          }); 

      console.log(filter_array); 

KYLE GWAPO佩羅JOKE RA