私はこのコードを持っています:
var app = {
items: [
[{
title: 'Overview',
id: 'dashboard'
}, {
title: 'Reports',
id: 'reports'
}],
[{
title: 'Customers',
id: 'customers'
}, {
title: 'Quotes',
id: 'quotes'
}, {
title: 'Sales',
id: 'sales'
}],
[{
title: 'Suppliers',
id: 'suppliers'
}, {
title: 'Purchases',
id: 'purchases'
}],
[{
title: 'Bank',
id: 'bank'
}, {
title: 'Projects',
id: 'projects',
disabled: true
}, {
title: 'Journal',
id: 'journal',
disabled: true
}]
]
}
var userDetails = {
IsAdmin: true
};
for (var x = 0; x < app.items.length; x++) {
app.items[x].filter(function (items) {
if (items.disabled || (userDetails.IsAdmin && items.id !== 'quotes')) {
var ind = app.items[x].indexOf(items);
app.items[x].splice(ind, 1);
}
});
}
console.log(app.items);
出力は、最後まで各配列に 1 つのオブジェクトが残っていることです。これは望ましくありません。私の計算では、単一のオブジェクト (引用符オブジェクト) が残っている必要があります。
関連する jsFiddle: http://jsfiddle.net/UdzEW/
何か案は?