如果休息服务响应返回 true ,我想从数组中删除索引,所以在下面的情况下,假设我们从休息服务中有 true ,我想从数组中删除 id 为“RA_ATTST_LANGUAGE”的对象。我尝试了下面的代码,但它没有删除丢失的内容?
main.js
MessageAdminNotificationFactory.getAttestationLanValidation().then(function(response){
var data = response.data;
console.log('attestation',data);
if(data){
angular.forEach($scope.adminDataSource,function(value,$index){
if(value.id === 'RA_ATTST_LANGUAGE'){
$scope.adminDataSource.splice($index, 1);
}
console.log('dropdown',value.id);
});
}
});
$scope.adminDataSource = [{
"uid": null,
"index": 0,
"selected": null,
"expanded": null,
"id": "RA_PLTFRM_NOTIF",
"text": "Platform Maintenance Notification",
"parentId": null,
"items": null
}, {
"uid": null,
"index": 0,
"selected": null,
"expanded": null,
"id": "RA_ATTST_LANGUAGE",
"text": "Attestation Language",
"parentId": null,
"items": null
}]
最佳答案
$scope.adminDataSource = $scope.adminDataSource.filter(
function(value){
return value.id !== 'RA_ATTST_LANGUAGE';
})
Array.filter是要走的路。过滤掉任何计算结果为 false 的内容;
关于javascript - 如何使用 angularjs 从对象数组中删除项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37309092/