2017-09-19 47 views
2

我想我DepartmentTmp變量NG-模型(末成分)DEPARTEMENT過濾器,因爲這一個類似的代碼:(部門choosen =選擇)我怎樣才能在NG-模型AngularJS使用過濾器

sk-input-select(ng-model='vm.DepartmentTmp.filters.#DEPARTMENT CHOSEN#', choices='refs.departmentList', ng-change='refs.search()', placeholder='Sélectionner...', allow-clear='true') 

這裏是DepartmentList:

[{"id":1,"label":"Direction","code":"DIR"}, 
{"id":6,"label":"Pôle commercial","code":"COM"}, 
{"id":5,"label":"Pôle communication/marketing","code":"MAR"},{"id":3,"label":"Pôle ingénierie logicielle","code":"ING"}, 
{"id":4,"label":"Pôle web","code":"WEB"}, 
{"id":2,"label":"Service des ressources humaines","code":"RH"}] 

這裏是什麼樣子DepartmentTmp。正如你所看到的,在這個部門的信息裏面有一個名爲「departement」的屬性。

[{"id":9,"username":"alexandra.bauchart","lastName":"Bauchart","firstName":"Alexandra","phone":"","isDeleted":false,"roles":[{"id":2,"label":"ROLE_AGENT","canRegulateCounter":false,"canSeeRequestAttachFile":false}],"department":{"id":5,"label":"Pôle communication/marketing","code":"MAR"},"enabled":true,"accountNonExpired":true,"accountNonLocked":true,"credentialsNonExpired":true,"label":"Alexandra Bauchart","abregate":"AB"}, 
    {"id":4,"username":"alexandre.bay","lastName":"Bay","firstName":"Alexandre","phone":"","isDeleted":false,"roles":[{"id":2,"label":"ROLE_AGENT","canRegulateCounter":false,"canSeeRequestAttachFile":false}],"department":{"id":3,"label":"Pôle ingénierie logicielle","code":"ING"},"enabled":true,"accountNonExpired":true,"accountNonLocked":true,"credentialsNonExpired":true,"label":"Alexandre Bay","abregate":"AB"}, 
    {"id":2,"username":"benjamin.ruef","lastName":"Ruef","firstName":"Benjamin","phone":"","isDeleted":false,"roles":[{"id":2,"label":"ROLE_AGENT","canRegulateCounter":false,"canSeeRequestAttachFile":false}],"department":{"id":3,"label":"Pôle ingénierie logicielle","code":"ING"},"enabled":true,"accountNonExpired":true,"accountNonLocked":true,"credentialsNonExpired":true,"label":"Benjamin Ruef","abregate":"BR"}, 
    {"id":7,"username":"corentin.dauvier","lastName":"Dauvier","firstName":"Corentin","phone":"","isDeleted":false,"roles":[{"id":2,"label":"ROLE_AGENT","canRegulateCounter":false,"canSeeRequestAttachFile":false}],"department":{"id":3,"label":"Pôle ingénierie logicielle","code":"ING"},"enabled":true,"accountNonExpired":true,"accountNonLocked":true,"credentialsNonExpired":true,"label":"Corentin Dauvier","abregate":"CD"}, 
    {"id":6,"username":"dorothee.wenehoua","lastName":"Wenehoua","firstName":"Dorothee","phone":"","isDeleted":false,"roles":[{"id":7,"label":"ROLE_RH","canRegulateCounter":true,"canSeeRequestAttachFile":true}],"department":{"id":2,"label":"Service des ressources humaines","code":"RH"},"enabled":true,"accountNonExpired":true,"accountNonLocked":true,"credentialsNonExpired":true,"label":"Dorothee Wenehoua","abregate":"DW"}, 
    {"id":3,"username":"florian.gourmelen","lastName":"Gourmelen","firstName":"Florian","phone":"","isDeleted":false,"roles":[{"id":3,"label":"ROLE_RESP","canRegulateCounter":false,"canSeeRequestAttachFile":false}],"department":{"id":3,"label":"Pôle ingénierie logicielle","code":"ING"},"enabled":true,"accountNonExpired":true,"accountNonLocked":true,"credentialsNonExpired":true,"label":"Florian Gourmelen","abregate":"FG"}, 
    {"id":5,"username":"hatem.bellagi","lastName":"Bellagi","firstName":"Hatem","phone":"","isDeleted":false,"roles":[{"id":6,"label":"ROLE_DIR","canRegulateCounter":false,"canSeeRequestAttachFile":false}],"department":{"id":1,"label":"Direction","code":"DIR"},"enabled":true,"accountNonExpired":true,"accountNonLocked":true,"credentialsNonExpired":true,"label":"Hatem Bellagi","abregate":"HB"}, 
    {"id":8,"username":"richard.ratiman","lastName":"Ratiman","firstName":"Richard","phone":"","isDeleted":false,"roles":[{"id":3,"label":"ROLE_RESP","canRegulateCounter":false,"canSeeRequestAttachFile":false}],"department":{"id":5,"label":"Pôle communication/marketing","code":"MAR"},"enabled":true,"accountNonExpired":true,"accountNonLocked":true,"credentialsNonExpired":true,"label":"Richard Ratiman","abregate":"RR"},  
    {"id":12,"username":"rodolphe.bertolini","lastName":"Bertolini","firstName":"Rodolphe","phone":"","isDeleted":false,"roles":[{"id":2,"label":"ROLE_AGENT","canRegulateCounter":false,"canSeeRequestAttachFile":false}],"department":{"id":3,"label":"Pôle ingénierie logicielle","code":"ING"},"enabled":true,"accountNonExpired":true,"accountNonLocked":true,"credentialsNonExpired":true,"label":"Rodolphe Bertolini","abregate":"RB"}, 
    {"id":10,"username":"simon.larthe","lastName":"Larthe","firstName":"Simon","phone":"","isDeleted":false,"roles":[{"id":2,"label":"ROLE_AGENT","canRegulateCounter":false,"canSeeRequestAttachFile":false}],"department":{"id":5,"label":"Pôle communication/marketing","code":"MAR"},"enabled":true,"accountNonExpired":true,"accountNonLocked":true,"credentialsNonExpired":true,"label":"Simon Larthe","abregate":"SL"}, 
    {"id":11,"username":"sonia.touahri","lastName":"Touahri","firstName":"Sonia","phone":"","isDeleted":false,"roles":[{"id":7,"label":"ROLE_RH","canRegulateCounter":true,"canSeeRequestAttachFile":true}],"department":{"id":2,"label":"Service des ressources humaines","code":"RH"},"enabled":true,"accountNonExpired":true,"accountNonLocked":true,"credentialsNonExpired":true,"label":"Sonia Touahri","abregate":"ST"}, 

所以你可以明白,我想保持在DepartmentTmp只有其中DEPARTEMENT與之相匹配的DEPARTEMENT在過濾器中選擇的用戶。

感謝,

薩科卡介苗

回答

1

使用特定的NG-模型變量名稱並設置部門ID的價值:如:ng-model="vm.choosenDepartment" ng-value="department.id" 所以你可以按部門ID使用過濾器,如:

{department: {id: vm.choosenDepartment}} 

與正常的HTML & NG選項:

<b>Choose pole:</b> 
<select ng-model='vm.choosenDepartment' ng-options="item.id as item.label for item in vm.departmentList track by item.id"> 
</select> 
<br/><b>result</b> 
<ul> 
<li ng-repeat="i in (vm.departmentTmp | filter:{department: {id: vm.choosenDepartment}})">{{i.label}}</li> 

https://embed.plnkr.co/IELGfEvc0Q3h5a7x0MDl/

+0

謝謝您的回答,除了在一個情況下,它的工作完美:我不能沒有我選擇了一個過濾器中進行選擇。 當我使用沒有過濾器,所有的用戶應該顯示它的作品,當我第一次運行的網絡,但一旦我選擇了部門過濾器我不能回到0. 謝謝尼古拉斯 –

+0

@NicolasGuerin只是在部門清單'{ 「id」:undefined, 「label」:「All」, 「code」:「All」 }'中添加id = undefined的項目'here plunker https://plnkr.co/編輯/ IELGfEvc0Q3h5a7x0MDl?p = preview – Fetrarij

+1

我創建了一個按鈕,刪除vm.choosenDepartmen,當我點擊它(帶有一個漂亮的垃圾箱圖標aha)感謝幫助它現在是好的。 –