【发布时间】:2017-03-06 20:01:06
【问题描述】:
您好,我想合并和匹配两个 json 对象。我想使用 Angular 方式。任何帮助将不胜感激。谢谢大家。这是一个例子:
// 第一个json对象 { "用户 ID":"john.davis", “edpi”:空, “用户应用程序”:[ { "名称":"名称 3", "链接":"/Protect3.php" }, { "名称":"名称 5", "链接":"/Admin/Launch.html" }, { "名称":"名称 2", "链接":"aaap/defaultBH.php" } ] } // 第二个json对象 [ { “颜色”:“颜色1”, "icon": "content/images/icons/administrator.svg", “名称”:“名称 5” }, { “颜色”:“颜色3”, "icon": "content/images/icons/administrator.svg", “名称”:“名称 3” }, { “颜色”:“颜色2”, "icon": "content/images/icons/behavior.svg", “名称”:“名称 2” } ]希望得到这个
[ { "TokenName":"name3", "TokenLink":"../Protect3.asp", “颜色”:{ “颜色”:“颜色3”, "icon": "content/images/icons/administrator.svg", “匹配”:“名称 3” } }, { "名称":"名称 5", "链接":"/Admin/Launch.html", “颜色”:{ “颜色”:“颜色1”, "icon": "content/images/icons/administrator.svg", “匹配”:“名称 5” } }, { "名称":"名称 2", “链接”:“aaap/defaultBH.php” “颜色”:{ “颜色”:“颜色2”, "icon": "content/images/icons/behavior.svg", “匹配”:“名称 2” } } ]【问题讨论】:
-
在问题中详细说明您要达到的目标
-
在我当前的代码中,我已经成功合并了两个对象。但现在我想合并匹配的对象属性。下面是我合并两个对象的代码。
-
首先我使用 Angular http 拉取了两个 json 对象。然后我编写了一个函数将对象从第二个对象推送到第一个对象。函数 addColor (objectArray, colorArray, restrictedtemplate){ objectArray.forEach(function(object, index){ object.color = colorArray[index]; }); }; addColor($scope.restrictedapps, $scope.colors, $scope.unrestricteddata);
标签: javascript angularjs json