2015-04-15 82 views
1

我有一個數組:AngularJS:濾波器陣列對象按屬性名稱

$scope.default = [ 
    {name:'bigid',desc:'Incrementing ID using <code>BIGINT</code>'}, 
    {name:'timestamps',desc:'Add <code>TIMESTAMP</code> columns'}, 
    {name:'ntimestamps',desc:'Allow <code>TIMESTAMP</code> null'}, 
    {name:'softdelete',desc:'Support <code>SOFTDELETE<code>'}, 
    {name:'rem_token',desc:'Adds <code>remember_token</code>'} 
]; 

但是,我想過濾器,我有結果:

[ 
    {name:'bigid'}, 
    {name:'timestamps'}, 
    {name:'ntimestamps'}, 
    {name:'softdelete'}, 
    {name:'rem_token'} 
]; 

幫助我,請。我應該只能使用AngularJS過濾器來做到這一點嗎?

回答

1

您可以使用.map

$scope.default = [ 
    {name:'bigid',desc:'Incrementing ID using <code>BIGINT</code>'}, 
    {name:'timestamps',desc:'Add <code>TIMESTAMP</code> columns'}, 
    {name:'ntimestamps',desc:'Allow <code>TIMESTAMP</code> null'}, 
    {name:'softdelete',desc:'Support <code>SOFTDELETE<code>'}, 
    {name:'rem_token',desc:'Adds <code>remember_token</code>'} 
]; 

$scope.default = $scope.default.map(function (el) { 
    return {name: el.name}; 
}); 
+1

謝謝你。這正是我需要:) –