我有以下 C# LINQ 查询,需要将其移植到 Angular 2。
var groups = funds.OrderBy(g => g.DefaultGroupName).GroupBy(g => g.DefaultGroupName)
.Select(grp => new { GroupName = grp.Key, Funds = grp.ToList().OrderBy(f => f.ZOrder) });
这就是我目前所拥有的(不起作用)。正如您所看到的,我对 Angular 非常陌生,因此我们将不胜感激任何帮助或指导。
// get the list of funds, grouped by Default Group Name
getFundGroups(): Observable<FundGroup[]> {
const url = this.baseUrl;
const funds = this.http.get(url)
.map(response => <Fund[]>response.json())
.catch(this.handleError);
const groups = funds.groupBy(fund => fund.DefaultGroupName)
.flatMap(group => group.reduce((a, b) => [...a, ...b], []));
return groups;
}
最佳答案
您可以使用 LINQ for Angular
https://github.com/Angular-Public/ng2-linq
import * as Enumerable from 'linq';
然后在你的函数中你可以写这样的东西。
let groups = Enumerbable.from(funds).where(x => x.Active);
关于javascript - 将 .Net LINQ 查询转换为 Angular 2 TypeScript/JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42653517/