开发者

append new data to list vs request data and repopulate list

For instance adding new categories to a list.

Once a new category has been开发者_如何学编程 added, and successfully submitted to the db, should I use JS to directly append this value to the list or should I query the table again and repopulate the list?


You can do both. What's easiest will depend on what needs to be done to show the new category in the list. If it's simply adding the category name to the list, there's no need to reload the list. If you need to add it somewhere in between to maintain alphabetic order, it gets trickier. If adding a category means that many other elements are influenced by that and need to change as well, reloading the full list might be easier.

One disadvantage of reloading the full list is the possibility of duplicate code. You need the list plus markup the first time when you load the page and generate the HTML with PHP, and a second time when you reload the list using JavaScript. In such cases it's best to setup your scripts in a way that you can easily use the same code to request this list. Otherwise you'll be writing the same thing twice.


It depends on how many users will be using you system/application. If the concurrency level is too high and it is expected that there will be frequent addition of categories, then you would probably want to query the db to get the whole list and display it, but if this is not the case, then it should be OK to just append the present entry to the list.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜