我有一个可观察到的POJO数组:
export interface SearchList {
id?: number;
createDttm?: string;
updateDttm?: string;
name?: string;
value?: number;
type?: string;
}
我从后端获取的数组是下面的示例
[{"id":26,"createDttm":"2018-07-26T16:40:40.773","updateDttm":"2018-07-26T16:40:40.773","name":"APPROVALSTATUS1","value":1,"type":"APPROVAL_STATUS"},
{"id":27,"createDttm":"2018-07-26T16:40:40.846","updateDttm":"2018-07-26T16:40:40.846","name":"APPROVALSTATUS2","value":2,"type":"APPROVAL_STATUS"},
{"id":10,"createDttm":"2018-07-26T16:40:39.48","updateDttm":"2018-07-26T16:40:39.48","name":"STATUS1","value":42,"type":"STATUS"},
{"id":21,"createDttm":"2018-07-26T16:40:40.379","updateDttm":"2018-07-26T16:40:40.379","name":"QUEUE1","value":3,"type":"QUEUE"},
{"id":24,"createDttm":"2018-07-26T16:40:40.624","updateDttm":"2018-07-26T16:40:40.624","name":"QUEUE2","value":6,"type":"QUEUE"},
{"id":23,"createDttm":"2018-07-26T16:40:40.542","updateDttm":"2018-07-26T16:40:40.542","name":"QUEUE3","value":5,"type":"QUEUE"},
{"id":16,"createDttm":"2018-07-26T16:40:39.965","updateDttm":"2018-07-26T16:40:39.965","name":"STATUS2","value":60,"type":"STATUS"},
{"id":7,"createDttm":"2018-07-26T16:40:39.239","updateDttm":"2018-07-26T16:40:39.239","name":"STATUS3","value":32,"type":"STATUS"},
{"id":8,"createDttm":"2018-07-26T16:40:39.318","updateDttm":"2018-07-26T16:40:39.318","name":"STATUS4","value":40,"type":"STATUS"},
{"id":15,"createDttm":"2018-07-26T16:40:39.883","updateDttm":"2018-07-26T16:40:39.883","name":"STATUS5","value":51,"type":"STATUS"},
{"id":12,"createDttm":"2018-07-26T16:40:39.642","updateDttm":"2018-07-26T16:40:39.642","name":"STATUS6","value":44,"type":"STATUS"},
{"id":18,"createDttm":"2018-07-26T16:40:40.142","updateDttm":"2018-07-26T16:40:40.142","name":"STATUS7","value":100,"type":"STATUS"}]
在我的父组件中,我正在发送一个ngrx分派操作以获取上述数据。我得到了以上数据。
然后我想通过数组'STATUS','APPROVAL_STATUS'和'QUEUE'来过滤它们。
我还希望按名称(按字母升序)对它们进行排序,然后将其发送到子组件(哑组件)
//dispatching action here
const SearchLists =
this.store.select(fromStore.getSearchListData);
//SearchLists has the array. Have to filter and sort here
statusList: Observable<SearchList[]>; //this will contain objects filtered by type=='STATUS'
queueList: Observable<SearchList[]>; //this will contain objects filtered by type=='QUEUE'
approvalStatusList:Observable<SearchList[]>; //this will contain objects filtered by type=='APPROVSAL_STATUS'
this.statusList = SearchLists.pipe(map(lists =>
lists.filter(list =>list.type =='STATUS')));
this.queueList= SearchLists.pipe(map(lists =>
lists.filter(list =>list.type =='QUEUE')));
this.approvalStatusList= SearchLists.pipe(map(lists =>
lists.filter(list =>list.type =='APPROVAL_STATUS')));
//How to sort by alphabetical after filtering and send it to child component on load so I can bind to listbox
我的问题是关于通过RXJS运算符对可观察流进行过滤和排序的组合,因此标记为重复的问题不适用于我的,因为那是普通的js。