我想通过ng-model中的部分过滤我的DepartmentTmp
变量(最后的内容),代码与此类似:(部门选择=选择)
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
中保留部门与过滤器中选择的部门匹配的用户。
谢谢,
Nicolas Guerin
答案 0 :(得分:1)
使用特定的ng-model变量名称并将department id设置为value:例如: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>