2015-03-31 53 views

回答

2

如果你需要構造一個對象存儲在變量中的動態密鑰,您應該使用bracket notation

$scope.$watch('status', function(){ 
    var filter = {}; 
    filter[$scope.filterby.val] = $scope.status; 
    $scope.filtered = $filter('filter')($scope.users, filter); 
    console.log($scope.filtered); 
}); 

演示:http://jsfiddle.net/n925b20L/2/