2017-05-25 183 views
1

我在使用下面的json對象過濾我的表時遇到了問題。 它過濾了一些關鍵值,但是如果我的json被嵌套,它將無法工作。 我相信我做錯了什麼和愚蠢的。帶有嵌套json的Angularjs過濾器

繼承人一樣的小提琴。下面https://jsfiddle.net/pnypxhj8/1/

是我的JSON對象:

[ 
{ 
    "EmpId": "3901", //----> Filter works on this 
    "SubmitDate": "30/04/2017", //----> Filter works on this 
    "Employee": "John", //----> Filter works on this 
    "ProdRequest": [{ 
      "ProdName": "Mac Air laptop - Apple", 
      "ManagersApproval": { 
       "Status": "Approved", //----> But Doesnt works on this 
       "ManagersDetails": [{ 
         "Name": "Steve Rock", 
         "Email": "[email protected]" 
        }, 
        { 
         "Name": "Mary Nuts", 
         "Email": "[email protected]" 
        } 
       ], 
       "Comments": "" 
      }, 
      "AdminApproval": { 
       "Status": "Pending", 
       "AdminDetails": [{ 
         "Name": "Hardy Lee", 
         "Email": "[email protected]" 
        }, 
        { 
         "Name": "Moss Grant", 
         "Email": "[email protected]" 
        } 
       ], 
       "Comments": "" 
      }, 
      "RequestStatus": "Pending" 
     }, 
     { 
      "ProdName": "Note Book - Large", 
      "ManagerApproval": { 
       "Status": "Approved", 
       "Approver": [{ 
        "Name": "Jet Lee", 
        "Email": "[email protected]" 
       }], 
       "Comments": "Approved by Jet Lee" 
      }, 

      "AdminApproval": { 
       "Status": "Approved", 
       "AdminDetails": [{ 
         "Name": "Hardy Lee", 
         "Email": "[email protected]" 
        }, 
        { 
         "Name": "Moss Grant", 
         "Email": "[email protected]" 
        } 
       ], 
       "Comments": "" 
      }, 
      "RequestStatus": "Completed" 
     } 
    ] 
}, 
{ 
    "EmpId": "550", 
    "SubmitDate": "22/04/2017", 
    "Employee": "Mary Kom", 
    "ProdRequest": [{ 
      "ProdName": "Seagate Harddisk 500TB", 
      "ManagersApproval": { 
       "Status": "Approved", 
       "ManagersDetails": [{ 
         "Name": "Steve Rock", 
         "Email": "[email protected]" 
        } 
       ], 
       "Comments": "" 
      }, 
      "AdminApproval": { 
       "Status": "Approved", 
       "AdminDetails": [{ 
         "Name": "Hardy Lee", 
         "Email": "[email protected]" 
        }, 
        { 
         "Name": "Moss Grant", 
         "Email": "[email protected]" 
        } 
       ], 
       "Comments": "" 
      }, 
      "RequestStatus": "Approved" 
     }, 
     { 
      "ProdName": "Note Book - Large", 
      "ManagerApproval": { 
       "Status": "Approved", 
       "Approver": [{ 
        "Name": "Jet Lee", 
        "Email": "[email protected]" 
       }], 
       "Comments": "Approved by Jet Lee" 
      }, 

      "AdminApproval": { 
       "Status": "Approved", 
       "AdminDetails": [{ 
         "Name": "Hardy Lee", 
         "Email": "[email protected]" 
        }, 
        { 
         "Name": "Moss Grant", 
         "Email": "[email protected]" 
        } 
       ], 
       "Comments": "" 
      }, 
      "RequestStatus": "Completed" 
     } 
    ] 
} 

]

+2

你能解釋一下它的數據是沒有得到映射和你真正想實現什麼? –

+0

數據正在映射..但它沒有得到過濾 「狀態」:「已批准」,// ---->但是如果答案是正確的,您是否可以標記爲已接受但不適用於此 – nipiv

+0

@nipiv? –

回答

2

第一:你有對象屬性一個錯字。您的篩選器上有ManagerApproval,但數據中包含ManagersApproval(含S)屬性。

二:過濾器應爲ng-repeat="a in data.ProdRequest | filter:{ProdName: prodName, ManagerApproval: { Status: managerApproval }}"

這裏的工作小提琴:https://jsfiddle.net/pnypxhj8/3/