【问题标题】:Getting Season Stats with Falcor使用 Falcor 获取赛季统计数据
【发布时间】:2016-08-05 09:34:38
【问题描述】:

使用 Falcor 和 Falcor 路由器获取赛季统计数据的最佳方法是什么?

我的季节数据源输出如下所示的数据:

{ id: 'recNMJfs4sqiJshna',
   fields: {
     Wins: 23,
     Losses: 51,
     Team: [ 'reckEYqAz3r8pUtUg' ],
     ... 
}

我的 id 是 guid,并且我有一个正在运行的 teamsById 路线,可以返回季节 guid。但是,为了防止出现大量重复的路线和代码,我正在尝试创建一个 seasonsIndex 路线,看起来像这样:

seasonIndex[0..10][year] or [seasonIndex[0..10]["2016"]

我可以在其中选择特定年份的季节数据源中的数据。希望我可以创建这样的输出:

seasonIndex: {
   teamGuid: {
      2016: {
         Wins: 23,
         Losses: 51,
         ...
      },
      2015: {
         ...
      }
   },
   ...
 },
 teamById: {
    teamGuid: {
        Name: Team Name
    }
 }

我无法确定构建此模型响应所需的路线。因为我不确定如何从不同赛季的数据源中获取数据并将其与独特的球队指导相关联,并且仍然能够参考赛季数据中的特定值,例如胜利、失败或获胜百分比。

【问题讨论】:

    标签: falcor falcor-router


    【解决方案1】:

    您需要按要公开的字段构建路由。例如,对于wins 字段:

    {
        route: "seasonIndex[{keys:teams}][{keys:years}].wins",
        get(pathSet) {
            const results = []
            for (team of pathSet.teams) {
                for (year of pathSet.years) {
                    const wins = ... // get the wins for that team and year from the data source
                    results.push({
                        path: ["seasonIndex", team, year, "wins"],
                        value: wins
                    })
                }
            }
        }
    }
    

    wins 的路由和losses 的路由最终可能会相似,因此您可以像这样折叠它们:

    {
        route: "seasonIndex[{keys:teams}][{keys:years}][{keys:property}]",
        get(pathSet) {
            const results = []
            for (team of pathSet.teams) {
                for (year of pathSet.years) {
                    for (property of pathSet.properties) {
                        const value = ... // get the value of the property for that team and year from the data source
                        results.push({
                            path: ["seasonIndex", team, year, property],
                            value
                        })
                    }
                }
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-06-14
      • 2012-02-28
      • 1970-01-01
      • 1970-01-01
      • 2019-10-24
      • 2023-04-02
      • 1970-01-01
      相关资源
      最近更新 更多