我是AngularJS的新手。我正在尝试分配JSON对象,并且我正在使用Object.assign分配JSON对象。但是我无法得到想要的结果
请帮助我获得结果。



'use strict'

let one ={"Start":"11","Dashboard":"1","Settings":"2","Support":"3","Trunk":"4","Routing":"5","Solutions":"6","Accounting":"7","Statistic":"8","Marketing":"9","Profile":"10"};
let two = {"Settings":{"Basic Settings":"1","Number Range":"2","Employess":"3","Message Fulfillment":"4"},"Support":{"All Contacts":"5","Detail Approval":"6","Incomplete Signup":"7","Settings":"8"},"Trunk":{"My Tickets":"9","All Tickets":"10"}};

let three	=	{"Settings":{"Basic Settings":{"My Information":"1","Bank Information":"2"}}};

let four = Object.assign({}, one, two, three);

console.log(JSON.stringify(four));

最佳答案

尝试这个 :



function mergeObjects() {
    var merged_obj = {};
    for (i in arguments) {
        obj = arguments[i];
        for (j in obj) {
                merged_obj[j] = obj[j];
        }
    }
    return merged_obj;
}

var one ={"Start":"11","Dashboard":"1","Settings":"2","Support":"3","Trunk":"4","Routing":"5","Solutions":"6","Accounting":"7","Statistic":"8","Marketing":"9","Profile":"10"};
var two = {"Settings":{"Basic Settings":"1","Number Range":"2","Employess":"3","Message Fulfillment":"4"},"Support":{"All Contacts":"5","Detail Approval":"6","Incomplete Signup":"7","Settings":"8"},"Trunk":{"My Tickets":"9","All Tickets":"10"}};

var three = {"Settings":{"Basic Settings":{"My Information":"1","Bank Information":"2"}}};

var mergedObj = mergeObjects(one, two, three);
console.log(mergedObj);

07-27 18:57