I need to dynamically update a table in my AngularJS app, based on what the user inputs. I have an updateCategory function that is invoked by ng-change in the view and should return a new array to vm.portfolioData in the controller.
The el.serviceList provides a property, serviceStatus, which provides a string value, which then needs to be checked if it is included in a object property in a second array, actionStatus:
function updateCategory(obj, position) {
vm.portfolioData = patents;
vm.portfolioData = vm.portfolioData.filter(function(el){
return el.serviceList.filter(function(item){
//item.serviceStatus: "Epct available"
//NEED TO RETURN EL IF STATUS IS CONTAINED IN SECOND ARRAY
}
})
}
Second array
actionStatus: [
{name: 'Epct available'},
{name: 'Epct saved'},
{name: 'Form 1200 saved'},
{name: 'Epct rejected'},
{name: 'Show price'},
{name: 'Open for Renewal'},
{name: 'Form 1200 generating'}
]
Question
How do I return the new filtered array once I have checked if the serviceStatus value is contained in any of the objects property name in the second array?
Try this:
const serviceList = [
{serviceStatus: 'Epct available'},
{serviceStatus: 'Epct not available'},
];
const actionStatus = [
{name: 'Epct available'},
{name: 'Epct saved'},
{name: 'Form 1200 saved'},
{name: 'Epct rejected'},
{name: 'Show price'},
{name: 'Open for Renewal'},
{name: 'Form 1200 generating'}
];
const actionStatusStrings = actionStatus.map(item => item.name);
const filteredArray = serviceList.filter(item => {
return actionStatusStrings.includes(item.serviceStatus);
});
Regarding your case:
function updateCategory(obj, position) {
vm.portfolioData = patents;
const actionStatusStrings = actionStatus.map(item => item.name);
vm.portfolioData = vm.portfolioData.filter(el => {
return el.serviceList.find(item => {
return actionStatusStrings.includes(item.serviceStatus);
});
})
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With