2016-04-14 39 views
1

使用Falcor和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 
    } 
} 

我很難弄清楚我需要建立這個模型響應的路線。因爲我不確定如何將數據從不同季節的數據源中提取出來,並將其與獨特的團隊指導相關聯,並且仍能夠在季節數據中引用特定值,例如Wins,Losses或Winning Percentage。

回答

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 
        }) 
       } 
      } 
     } 
    } 
}