I've array of objects oDataSet
and aProperties
object and I want to match the identical values that are found in aPropertis
and and In oDataSet
and create the aSelectedDataSet which in beginning is an empty object
How it's recommend to do it in JS/Jquery
Note: there shouldnt be any hardcoded property in the loops/solution to do the match the aProperties is contain this value but it can be change (and of course there should be match in the oData object...)
For clarification Following is example how the objects is built
http://jsfiddle.net/4rh6tt25/5/
This is the input
//This is given array of object which can be many ,here I put just two instance in the array for demonstration purpose
var oDataSet = [{
__metadata: {
aaa: 111,
bbb: 222
},
to_ExcludedTerms: {results: []},
to_ListTypeGroupAssignment: {
results: [
{
AuthorisationGroup: 'AuthorisationGroup 1',
ListTypeGroup: 'ListTypeGroup1',
ListTypeGroupDescription: 'ListTypeGroupDescription 1',
ParentKey: '8ae25d47-c3cc-4ee3-a040-ea00505692111',
__metadata: {}
},
{
AuthorisationGroup: 'AuthorisationGroup 2',
ListTypeGroup: 'ListTypeGroup2',
ListTypeGroupDescription: 'ListTypeGroupDescription 2',
ParentKey: '34bcdc74-ab42-4538-8657-0a2b0473fcb7',
__metadata: {}
},
{
AuthorisationGroup: 'AuthorisationGroup 3',
ListTypeGroup: 'ListTypeGroup3',
ListTypeGroupDescription: 'ListTypeGroupDescription 3',
ParentKey: '34bcdc74-ab42-4538-8657-0a2b0473fcb5',
__metadata: {}
}
]
}
}, {
//This is the second instance of the object with same keys but different values
__metadata: {
aaa: 333,
bbb: 444
},
to_ExcludedTerms: {results: []},
to_ListTypeGroupAssignment: {
results: [
{
AuthorisationGroup: 'AuthorisationGroup 6',
ListTypeGroup: 'ListTypeGroup6',
ListTypeGroupDescription: 'ListTypeGroupDescription 6',
ParentKey: '8ae25d47-c3cc-4ee3-a040-ea00505692116',
__metadata: {}
},
{
AuthorisationGroup: 'AuthorisationGroup 7',
ListTypeGroup: 'ListTypeGroup7',
ListTypeGroupDescription: 'ListTypeGroupDescription 7',
ParentKey: '34bcdc74-ab42-4538-8657-0a2b0473fcb7',
__metadata: {}
},
{
AuthorisationGroup: 'AuthorisationGroup 8',
ListTypeGroup: 'ListTypeGroup8',
ListTypeGroupDescription: 'ListTypeGroupDescription 8',
ParentKey: '34bcdc74-ab42-4538-8657-0a2b0473fcb8',
__metadata: {}
}
]
}
}
];
//This is the values which I should search find in oDataSet
//The to_ListTypeGroupAssignment or other property which under the same structure
//should be with the following path but under the results which is the only
//hardcoded property
var aProperties = [
"to_ListTypeGroupAssignment/ListTypeGroup",
"to_ListTypeGroupAssignment/ListTypeGroupDescription"
]
This is the output
This is example of the output which should be build from the merge of both objects in the input above
var aSelectedDataSet = [
{
__metadata: {
aaa: 111,
bbb: 222
},
to_ListTypeGroupAssignment: {
results: [
{
ListTypeGroup: 'ListTypeGroup1',
ListTypeGroupDescription: 'ListTypeGroupDescription 1'
},
{
ListTypeGroup: 'ListTypeGroup2',
ListTypeGroupDescription: 'ListTypeGroupDescription 2',
},
{
ListTypeGroup: 'ListTypeGroup3',
ListTypeGroupDescription: 'ListTypeGroupDescription 3',
}
]
}
},
{
__metadata: {
aaa: 333,
bbb: 444
},
to_ListTypeGroupAssignment: {
results: [
{
ListTypeGroup: 'ListTypeGroup1',
ListTypeGroupDescription: 'ListTypeGroupDescription 1'
},
{
ListTypeGroup: 'ListTypeGroup2',
ListTypeGroupDescription: 'ListTypeGroupDescription 2',
},
{
ListTypeGroup: 'ListTypeGroup3',
ListTypeGroupDescription: 'ListTypeGroupDescription 3',
}
]
}
}
]
just to clarify from the comments below :)
The only thing that can be hard-coded is the results
.
Not any property name like ListTypeGroup& ListTypeGroupDescription
This should be generic and read from aProperties
The structure of you look at the oData should be like following
property(like -> to_ListTypeGroupAssignmen)
results(hardcoded & mandatory in every exist object)
properties(like ListTypeGroup& ListTypeGroupDescription with there values)
If I need to make it more clear please let me know How,which additional info I should add...This is after I update the question as much as possible...