我正在从一个从JSON端点获取数据的解析器中获得一个"product"数组。
ngOnInit() {
this.products = this._route.snapshot.data.products;
console.log('products: ', this.products);
}
这个数组中的一个对象是以下格式之一:
Translated text:One of the objects in this array is in one of the following formats:
{
"id": 3645,
"date": "2018-07-05T13:13:37",
"date_gmt": "2018-07-05T13:13:37",
"guid": {
"rendered": ""
},
"modified": "2018-07-05T13:13:37",
"modified_gmt": "2018-07-05T13:13:37",
"slug": "vpwin",
"status": "publish",
"type": "matrix",
"link": "",
"title": {
"rendered": "VPWIN"
},
"content": {
"rendered": "",
"protected": false
},
"featured_media": 0,
"parent": 0,
"template": "",
"better_featured_image": null,
"acf": {
"domain": "SMB",
"ds_rating": "3",
"dt_rating": ""
},
...
},
我想做的是根据字段对这个数组进行排序。在AngularJS的旧时代,我只需在模板中使用一个设置为此字段的管道即可。显然,在Angular中已经删除了这个功能,从我的研究来看,首选方法是对数据本身进行排序,例如在中。
但是我无法弄清楚如何按对进行排序。