Alright, let's dive into the structure of these objects:
custom_fields:{
21:{
edit:true
required:true
show:true
}
}
In my Angular controller, this object is stored under $scope.page.custom_fields
. Within this object, there is another structure like so:
custom_fields:{
21:{
edit:true
required:true
show:true
}
22:{
edit:true
required:true
show:true
}
data:[
0:{
display_name:"Text"
id:21
name:"Text"
value:[
0:{"TextHere"}
]
}
1:{
display_name:"Text"
id:22
name:"Text"
value:[
0:{"TextHere"}
]
}
]
}
This nested structure is saved as follows:
$scope.page.custom_fields.data = response.data.custom_fields;
The first object consists of sub-objects while the second one contains an array of objects. Now I need to assign the keys from the data object to match the keys in the custom fields object, resulting in a consolidated view like this:
custom_fields:{
21:{
edit:true
required:true
show:true
display_name:"Text2"
id:21
name:"Text"
value:[
0:{"TextHere"}
]
}
}
This assignment should happen within the Angular controller. Each ID from the data array must align with a specific key in custom_fields (e.g., 21:{}
matches with data[0:{id:21}]
)
Since the order is maintained by PHP during processing, a foreach loop in JavaScript is not necessary. Simply sequentially assigning each key from custom_fields.data
to its corresponding key in custom_fields
will achieve the desired outcome.