在通过UI更改数据库时刷新前端UI的最佳做法是什么?(What is the best practice for refreshing front-end UI when making changes the the database through the UI? [closed])
我期望了解在同时更新UI和数据库值时的最佳实践。
设置
我在前端有一个表,它是列表中的项目列表:
- ID
- 名称
- 创建日期
- 收藏夹按钮(星号)
加载页面时,此列表通过axios从数据库中提取(类似于Ajax)。 收藏夹按钮是更改类的用户的切换,并且还更新数据库。 我试图了解更新UI和数据库的最佳实践。
目前,逻辑是这样的:
- 初始列表已加载到页面上
- 用户单击其中一行上的收藏夹按钮
- UI javascript将更新发送到数据库以更改列表中单个项目的“最喜欢”值
- 一旦成功完成更改,后端会以200个成功代码进行响应
- 前端接收成功的更改,然后使用axios查询完整数据库列表以使用更新的数据刷新UI列表
这是刷新UI的正确方法吗? 我用这种方法看到的问题是很差的UI响应时间,如果我等待更新,然后在用户进行更改时再次查询数据库。
其他选项
我想过的另一个选择是更新UI列表,同时将更新请求发送到后端。 唯一的区别是我不会“重新查询”数据库以更新数据,因为它应该匹配。
I'm looking to understand the best practices when updating UI and Database values simultaneously.
The Set-up
I have a table on the front end which is a list of items with the columns:
- ID
- Name
- Create Date
- Favorite button (star)
This list is pulled from the database via axios (similar to Ajax) when the page is loaded. The favorite button is a toggle for the user that changes the class and also updates the database. I'm trying to understand the best practices for updating the UI and the database.
Currently, the logic goes like this:
- Initial list is loaded on the page
- The user clicks the favorite button on one of the rows
- The UI javascript sends the update to the database to change the "favorite" value for that single item in the list
- Once a successful change is made the back-end responds with 200 success code
- The front end receives the successful change and then uses axios to query the full database list to refresh the UI list with the updated data
Is this the correct method to refresh the UI? The problem I see with this method is poor UI response time if I'm waiting to both update and then again query the database while the user is making changes.
Other options
Another option I've thought about is to update the UI list while simultaneously sending the update request to the back-end. The only difference is I would not "re-query" the database to update the data since it should match.
原文:https://stackoverflow.com/questions/48235102
最满意答案
只需使用
display:table-cell
和display:table
for parent。
在这里小提琴: http : //jsfiddle.net/6jnte8da/2/Just use
display:table-cell
in conjunction withdisplay:table
for parent.
Fiddle here: http://jsfiddle.net/6jnte8da/2/
相关问答
更多-
div内的垂直中心(Vertical center inside div)[2021-03-05]
只需使用display:table-cell和display:table for parent。 在这里小提琴: http : //jsfiddle.net/6jnte8da/2/ Just use display:table-cell in conjunction with display:table for parent. Fiddle here: http://jsfiddle.net/6jnte8da/2/ -
你可以在img和line-height上使用vertical-align ,例如: .top { height: 150px; background-color: blue; } .container { float: right; line-height: 150px; } img { vertical-align: middle; }
DIV中的垂直中心文本(Vertical Centre Text in DIV)[2022-10-10]
这篇伟大的文章讨论了通过css垂直对齐文本的最佳方法之一: http://zerosixthree.se/vertical-align-anything-with-just-3-lines-of-css/ Great article that talks about one of the best ways to vertically align text via css: http://zerosixthree.se/vertical-align-anything-with-just-3-lines-of ...div中心div垂直(Center div inside a div vertically)[2022-08-11]
新答案 这是新的小提琴链接http://fiddle.jshell.net/795St/16/ CSS .green-block { background-color: #02A556; margin: 0 .25em 0 .25em !important; width: 1em; height: 0.5em; vertical-align: middle; position: relative; } .pull-right { display ...对我来说,最好的解决方案是使用display: table技术(正如我在你之前的问题中回答的那样): #playerlist { display: table; width: 100%; } .opponents_list { height: 3em; margin: 0.1em auto; background: #666; vertical-align: middle; display: table-row; } .opponent_list_bold_ ...只需添加display: table; 到#tabs-3 更新了演示 Just add display: table; to #tabs-3 Updated Demo