繁体   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