How to reorganize the json data and classify them according to the type of test questions?

the final rendering to the page is based on single selection, multi-selection, judgment, etc., to solve?

[
    {
        "createTime": "2018-03-31 18:54:48",
        "enable": "1",
        "keyword": "",
        "orderBy": "",
        "paperId": "10",
        "question": {
            "courseName": "",
            "createBy": "1",
            "createTime": "2018-03-10 14:15:34",
            "enable": "1",
            "id": "2",
            "keyword": "",
            "options": [
                {
                    "createTime": "2018-03-10 14:15:34",
                    "enable": "1",
                    "id": "5",
                    "keyword": "",
                    "optionCode": "A",
                    "optionText": "",
                    "orderBy": "",
                    "questionId": "2",
                    "remark": "",
                    "updateTime": "2018-03-10 14:15:34"
                },
                {
                    "createTime": "2018-03-10 14:15:34",
                    "enable": "1",
                    "id": "6",
                    "keyword": "",
                    "optionCode": "B",
                    "optionText": "",
                    "orderBy": "",
                    "questionId": "2",
                    "remark": "",
                    "updateTime": "2018-03-10 14:15:34"
                },
                {
                    "createTime": "2018-03-10 14:15:34",
                    "enable": "1",
                    "id": "7",
                    "keyword": "",
                    "optionCode": "C",
                    "optionText": "",
                    "orderBy": "",
                    "questionId": "2",
                    "remark": "",
                    "updateTime": "2018-03-10 14:15:34"
                },
                {
                    "createTime": "2018-03-10 14:15:34",
                    "enable": "1",
                    "id": "8",
                    "keyword": "",
                    "optionCode": "D",
                    "optionText": "",
                    "orderBy": "",
                    "questionId": "2",
                    "remark": "",
                    "updateTime": "2018-03-10 14:15:34"
                }
            ],
            "orderBy": "",
            "questionAnswer": "ABD",
            "questionTitle": "

", "questionType": "2", "remark": "", "updateBy": "1", "updateTime": "2018-03-10 14:15:34" }, "questionAnswer": "", "questionId": "2", "remark": "", "score": "5.00", "updateTime": "2018-03-31 18:54:48" }, { "createTime": "2018-03-31 18:54:48", "enable": "1", "keyword": "", "orderBy": "", "paperId": "10", "question": { "courseName": "", "createBy": "1", "createTime": "2018-03-26 11:35:41", "enable": "1", "id": "5", "keyword": "", "options": [], "orderBy": "", "questionAnswer": "", "questionTitle": "

1840

", "questionType": "4", "remark": "", "updateBy": "1", "updateTime": "2018-03-26 11:35:41" }, "questionAnswer": "", "questionId": "5", "remark": "", "score": "5.00", "updateTime": "2018-03-31 18:54:48" }, { "createTime": "2018-03-31 18:54:48", "enable": "1", "keyword": "", "orderBy": "", "paperId": "10", "question": { "courseName": "", "createBy": "1", "createTime": "2018-03-26 11:36:09", "enable": "1", "id": "6", "keyword": "", "options": [], "orderBy": "", "questionAnswer": "1840", "questionTitle": "

", "questionType": "3", "remark": "", "updateBy": "1", "updateTime": "2018-03-26 11:36:09" }, "questionAnswer": "", "questionId": "6", "remark": "", "score": "5.00", "updateTime": "2018-03-31 18:54:48" } ]
Feb.28,2021

do you mean to sort by .room.sorting Type ?

suppose there is a variable questions in the array you give, and collection

is sorted.
var collection = {};

questions.forEach(ques => (collection[ques.question.questionType] = collection[ques.question.questionType] || []).push(ques));

write separately and read more clearly

var collection = {};

questions.forEach(ques => {
  collection[ques.question.questionType] = collection[ques.question.questionType] || [];
  collection[ques.question.questionType].push(ques);
});

I think you want to traverse it for different questionType processing?

Menu