2017-11-13 4 views
0

のレコードが$scope.allEmployeeGroupsに一致するレコードを検索しようとしていますが、フィルタがレコードをフィルタリングしていないと確信していますが、すべてのレコードを返します。各レコードについて、indexOf == -1とすれば、それはすべきではないことが分かっています。私は何が間違っているのか分かりません。ここに私のコードは次のとおりです。フィルタはレコードをフィルタリングしていません

function getNonGroupEmployees() { 
    var arr = $scope.employees.filter(function (item) { 
     return $scope.allEmployeeGroups.indexOf(item.EmployeeId) === -1; 
    }) 
    return arr; 
} 

Employeeオブジェクト:

public System.Guid EmployeeId { get; set; } 
    public Nullable<System.Guid> SiteId { get; set; } 
    public string SiteName { get; set; } 
    public string DisplayName { get; set; } 
    public string FirstName { get; set; } 
    public string MiddleName { get; set; } 
    public string LastName { get; set; } 
    public string Suffix { get; set; } 
    public string Alias { get; set; } 
    public Nullable<System.DateTime> DOB { get; set; } 
    public string SsnLastFour { get; set; } 
    public string Email { get; set; } 
    public string UserName { get; set; } 
    public string Password { get; set; } 
    public bool IsActive { get; set; } 
    public bool IsLoginEnabled { get; set; } 
    public Nullable<System.DateTime> LastLogin { get; set; } 
    public Nullable<System.Guid> SignatureTypeId { get; set; } 
    public string SignatureType { get; set; } 
    public string NumberHome { get; set; } 
    public string NumberCell { get; set; } 
    public bool IsSuperUser { get; set; } 
    public bool IsDeleted { get; set; } 
    public System.DateTime Created { get; set; } 
    public System.DateTime LastModified { get; set; } 
    public Nullable<System.Guid> ModifiedByEmployeeId { get; set; } 
    public string ApiKey { get; set; } 

グループオブジェクト:

  public Guid EmployeeGroupId { get; set; } 
     public Guid SiteId { get; set; } 
     public Guid EmployeeId { get; set; } 
     public Guid SiteGroupId { get; set; } 
     public bool IsDeleted { get; set; } 
     public DateTime Created { get; set; } 
     public DateTime LastModified { get; set; } 
     public Guid? ModifiedByEmployeeId { get; set; } 
     public string SiteName { get; set; } 
     public string EmployeeName { get; set; } 
     public string SiteGroupName { get; set; } 
     public string ModifiedByEmployeeName { get; set; } 

どのような援助が大幅に高く評価されます。

答えて

0

.IndexOf()でオブジェクトを検索する代わりに、プロパティマッチングを使用します。 2つのオブジェクトに同じ参照がない場合、オブジェクトは一致しません。

次のコードブロックを試してみてください。ここで要求されるように

function getNonGroupEmployees() { 
     var arr = $scope.employees.filter(function (item) { 
      return $scope.allEmployeeGroups.find(function(p){ 
       return p.EmployeeId == item.EmployeeId 
      })=== null; 
     }) 
     return arr; 
} 

は、データ構造です:

従業員:

public System.Guid EmployeeId { get; set; } 
     public Nullable<System.Guid> SiteId { get; set; } 
     public string SiteName { get; set; } 
     public string DisplayName { get; set; } 
     public string FirstName { get; set; } 
     public string MiddleName { get; set; } 
     public string LastName { get; set; } 
     public string Suffix { get; set; } 
     public string Alias { get; set; } 
     public Nullable<System.DateTime> DOB { get; set; } 
     public string SsnLastFour { get; set; } 
     public string Email { get; set; } 
     public string UserName { get; set; } 
     public string Password { get; set; } 
     public bool IsActive { get; set; } 
     public bool IsLoginEnabled { get; set; } 
     public Nullable<System.DateTime> LastLogin { get; set; } 
     public Nullable<System.Guid> SignatureTypeId { get; set; } 
     public string SignatureType { get; set; } 
     public string NumberHome { get; set; } 
     public string NumberCell { get; set; } 
     public bool IsSuperUser { get; set; } 
     public bool IsDeleted { get; set; } 
     public System.DateTime Created { get; set; } 
     public System.DateTime LastModified { get; set; } 
     public Nullable<System.Guid> ModifiedByEmployeeId { get; set; } 
     public string ApiKey { get; set; } 

従業員グループansweへ

  public Guid EmployeeGroupId { get; set; } 
     public Guid SiteId { get; set; } 
     public Guid EmployeeId { get; set; } 
     public Guid SiteGroupId { get; set; } 
     public bool IsDeleted { get; set; } 
     public DateTime Created { get; set; } 
     public DateTime LastModified { get; set; } 
     public Guid? ModifiedByEmployeeId { get; set; } 
     public string SiteName { get; set; } 
     public string EmployeeName { get; set; } 
     public string SiteGroupName { get; set; } 
     public string ModifiedByEmployeeName { get; set; } 
+0

感謝。残念ながら、上記のコードはエラーをスローします。 –

+0

$ scope.allEmployeeGroupsリストに$ scope.employeesと同じ型オブジェクトが含まれていますか? – Syedur

+0

いいえ。オブジェクトが異なります。彼らが共有する唯一のものはEmployeeIdフィールドです。 –

0

感謝rはHereを見つけ、ここで最終的に働いていたものです:手助けしようとしているため

function getNonGroupEmployees() { 
    var result = $scope.employees.filter(function (o1) { 
     return !$scope.allEmployeeGroups.some(function (o2) { 
      return o1.EmployeeId === o2.EmployeeId;   // assumes unique id 
     }); 
    }) 
    return result; 
} 
関連する問題