1. First of all, there is a list of objects with the following structure
objectList=[
{
objectId:"object1", // Id
objectName: "1", //
parentId:"parent1", // Id
childId: "child1" // Id
},
{
objectId:"object2",
objectName: "2",
parentId:"parent1",
childId: "child1"
},
{
objectId:"object3",
objectName: "3",
parentId:"parent1",
childId: "child2"
},
{
objectId:"object4",
objectName: "4",
parentId:"parent1",
childId: "child3"
}]
The purpose of is to give a childId, to return all eligible objects in the objectList table.
this is not only as simple as filter, but also has an authList array to restrict:
the restriction rule is as follows (suppose the object whose childId="child1" is to be fetched from objectList and the value of type contains" seach""):
1. If the authList array is empty, ignore type, and directly get the result on Filter objectList,.
the result should be two objects, object1 and object2.
2. If the authList is not empty and the array structure is as follows, then you should do something on top of step 1:
authList=[
{
objectId:"object1",
childId: "child1",
type:"add,delete"
},
{
objectId:"object3",
childId: "child1",
type:"seach"
},
]
then the judgment should be based on the type field of the authList table at this time. The result should be object2 and object3. (it is not eligible that there is no seach, in the type of the first record of authList; the type of the second record has search, so the object3 is also added to the result);
could you tell me how to realize the above functions gracefully? I tried to write it for a while, and I felt that the code was quite complicated and made myself dizzy for a while. Ask the great god for advice.