So I would need to filter array and an array within this array.
So, we have an array -
arr: [
{
name: 'object',
array2: [
{
name: '1'
},
{
name: '2'
}
]
},
{
name: 'object 2',
array2: [
{
name: 'object'
}
]
}
]
I enter a value 2 in the filter, and the output, that I would like to have here is -
arr: [
{
name: 'object',
array2: [
{
name: '2'
}
]
},
{
name: 'object 2',
array2: []
}
]
I have the matching logic here, and it works on the outer level (the first level, where I have an object with name and array2 parameters). The inner level also works, but the issue here is that, if I filter the inner level, I'm not able to get back the initial state of the inner objet, that is. I have an input bar, if I enter 2, it's filtered just fine, but, if I remove 2, then it shows other elements from arr: [], but doesn't show filtered elements from array2: [].
Any ideas on how to fix this?
Link to jsFiddle with comments - http://jsbin.com/pupugoxebi/edit?html,js,output .
I coudl manually push in the new array, but this doesn't work because I have dynamic array, for example, it can have different properties, and writing manually won't solve it. Updated version - http://jsbin.com/bifolisefu/edit?html,js,output .