在 React 应用程序中在哪里转换数据 - 在 Express 中还是在前端使用 React?
Posted
技术标签:
【中文标题】在 React 应用程序中在哪里转换数据 - 在 Express 中还是在前端使用 React?【英文标题】:where to transform data in React app - in express or on front end with React? 【发布时间】:2017-11-24 03:19:26 【问题描述】:我有一个创建联赛的应用程序。我的 JSON 数据结构如下。 我想根据夹具数据创建一个排名表。 我应该遍历固定装置并在前端计算每个球员的联赛数据(我使用反应)还是在后端计算(快递)? 还是有更好的选择?
谢谢
const leagueData = [
"league_id":1,
"players": [
"player_id": 1, "name": "Paul Langley", "nickname": "Langers",
"player_id": 2, "name": "Anthony Gayton", "nickname": "Drax",
"player_id": 3, "name": "Mark Stiles", "nickname": "Raynaud",
"player_id": 4, "name": "Chris Corse", "nickname": "Eggbum",
"player_id": 5, "name": "Elna", "nickname": "Elna",
"player_id": 6, "name": "Craig Mant", "nickname": "Craigenhead",
"player_id": 7, "name": "Karl", "nickname": "Karl",
"player_id": 8, "name": "Chris Farrell", "nickname": "Fazza",
"player_id": 9, "name": "Paul Lynch", "nickname": "Paul",
"player_id": 10, "name": "Neil", "nickname": "Neil",
"player_id": 11, "name": "Dug Buchanen", "nickname": "Dug",
"player_id": 12, "name": "Justin", "nickname": "Justin",
"player_id": 13, "name": "Polish Builder", "nickname": "Pole"
],
"fixtures": [
"fixture_id":1,
"date": "17/05/2017",
"played":true,
"teams":
"team1": [1 ,2, 3, 4, 5],
"team2": [6, 7, 8, 9, 10]
,
"score1":10,
"score2":0
,
"fixture_id":2,
"date": "24/05/2017",
"played":false,
"teams":
"team1": [1 ,2, 3, 4, 5],
"team2": [6, 7, 8, 9, 10]
,
"score1":0,
"score2":0
]
]
【问题讨论】:
【参考方案1】:是的,您应该使用 .map (array) 函数在前端绘制视图
【讨论】:
【参考方案2】:我个人会在后端执行此操作。
更容易测试 客户端负载更少(首次绘制时间更快) 允许您随时重新构建/重构数据【讨论】:
以上是关于在 React 应用程序中在哪里转换数据 - 在 Express 中还是在前端使用 React?的主要内容,如果未能解决你的问题,请参考以下文章