簡體   English   中英

在另一個數組中添加javaScript數組

[英]add javaScript array in another array

我有javaScript數組保持元素記錄,其中包含唯一的elementIndex,我必須在同一個特定元素(相同的elementIdex)的相同javaScript數組中添加單個或多個組件。

該數組可以具有所需數量的元素,並且每個元素可以具有與該元素相關聯的一個或多個組件。

我已經成功完成了第一部分,我如何做第二部分...即添加與單個元素相關的組件記錄。

note元素和組件在單獨的javaScript函數中,但我有全局數組

這是我想要實現的(可能是JSON)

   QualificationElemenetsAndComponents[0] = {

         Element [
                 ElementIndex : "",
                 ElementMarkingSchemeTitle : "",
                 ElementAvailableMark: "",
                 ElementPassMark: "",
                 ElementDistinctionMark: "",
                 Component[0]= [ 
                               componentIndex="", 
                               componentMark =""
                               ], 
                 Component[1]= [ 
                               componentIndex="", 
                               componentMark =""
                               ], 
                 Component[2]= [ 
                               componentIndex="", 
                               componentMark =""
                               ], 
                    }

全局數組

 var selectedComponentList = [];

 var selectElementList = [];

元件

  $("#ElementTable").on("click", ".k1-grid-confirm", function () {

        var E_RecordId = $(this).data("id");
        var E_MarkingSchemeTitle = $("#" + E_RecordId + "_EMST").val();
        var E_AvailableMark = $("#" + E_RecordId + "_AM").val();
        var E_PassMark = $("#" + E_RecordId + "_PM").val();
        var E_MeritMark = $("#" + E_RecordId + "_MM").val();
        var E_DistinctionMark = $("#" + E_RecordId + "_DM").val();

        alert("elementRecordId " + E_RecordId + " E_MarkingSchemeTitle " + E_MarkingSchemeTitle + " E_AvailableMark " + E_AvailableMark + " E_PassMark " + E_PassMark + " E_MeritMark " + E_MeritMark + " E_DistinctionMark " + E_DistinctionMark);

        //add data to array//

        selectElementList.push({ ElementIndex: E_RecordId, ElementMarkingSchemeTitle: E_MarkingSchemeTitle, ElementAvailableMark: E_AvailableMark, ElementPassMark: E_PassMark, ElementMeritMark: E_MeritMark, ElementDistinctionMark: E_DistinctionMark });

        }
    });

零件

$("#ComponentSchemeTable").on("click", ".k-grid-confirm", function () {

        var recordId = $(this).data("id");
        var ComponentSchemeMark = $("#" + recordId + "_CM").val();
       //
        $(this).hide();

        $(this).siblings(".k-grid-input").hide();

        $(this).siblings(".k-grid-cancel").hide();

        $(this).siblings(".k-grid-Remove").show();

        //add data to array//
        selectedComponentList.push({ componentIndex: recordId, componentMark: ComponentSchemeMark });

         //push array to Selected Element

              ?????????????????????????????????????
        }
    });

非常感謝

定義一個刷新全局列表的函數:

// Elements
selectElementList.push({...});
refreshGlobalList();

// Components
selectedComponentList.push({...});
refreshGlobalList();

功能:

var globalList = [];
function refreshGlobalList() {
  globalList = selectElementList.concat(selectedComponentList);
}
arrayNum.push.apply(arrayNum, arrayValuTwo);
arrayNum.push.apply(arrayNum, arrayValuThree);

你可以嘗試這個,或者你可以嘗試這個

arrayNumber.push.apply(arrayNumber, arrayValueTwo.concat(arrayValueThree));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM