如何在对象中使用变量名?

时间:2017-05-26 13:19:21

标签: javascript object var

我想使用apple = theApples.trees.green访问我的对象的值。 例如,如果我自己指定完整路径它是var colorOfApple = "red"; apple = theApples.trees.colorOfApple; 但我想这样做:

.colorOfApple

问题是它是否尝试访问对象的colorOfApple但我希望值为{{1}}

1 个答案:

答案 0 :(得分:2)

这很简单,只有this.results = this.results.OrderByDescending(x => x.WinPercentage).ThenByDescending(x => x.Goals); var positionGroups = this.results.GroupBy(x => new { WinPercentage = x.WinPercentage, Goals = x.Goals }); int position = 1; foreach (var positionGroup in positionGroups) { foreach (var team in positionGroup) { team.Position = position; } position++; }