在级联删除数据库后删除用户界面数据的正确方法

时间:2022-10-19 21:50:25

I have the relation 1 Company has many Organisations

我有关系1公司有很多组织

My treeview with Organisations is shown on the left side in the user interface.

我的组织树视图显示在用户界面的左侧。

A "delete company"-button opens a modal delete dialog.

“删除公司”按钮打开模式删除对话框。

In the dialog I selected a company to delete and confirm.

在对话框中,我选择了要删除并确认的公司。

Now the company is deleted in the database with an ajax post.

现在公司在数据库中删除了一个ajax帖子。

if the result.success is true then I have 2 choices.

如果result.success为true,那么我有2个选择。

My question is now wich one is better and why?

我现在的问题是哪一个更好,为什么?

  1. Delete the whole organisation tree by doing $('#TreeView').empty(); which clears everything inside the div
  2. 通过执行$('#TreeView')删除整个组织树.lemp();它清除div内部的一切

  3. "Delete" the whole organisation tree by doing a $('#TreeView').load(UrlToGetTreeHierarchy) which should return an empty tree collection.
  4. 通过执行$('#TreeView')。load(UrlToGetTreeHierarchy)来“删除”整个组织树,它应该返回一个空的树集合。

Both has same effect but point 2 accesses the database again.

两者都有相同的效果,但第2点再次访问数据库。

What is best practice in such a case?

在这种情况下,最佳做法是什么?

1 个解决方案

#1


0  

Definitely number 1. There's no benefit in asking for an empty dataset. That would require a request, a database query and then a response. The first method simply clears the data that has already been confirmed to be deleted.

绝对数字1.要求空数据集没有任何好处。这需要一个请求,一个数据库查询,然后一个响应。第一种方法只是清除已经确认要删除的数据。

#1


0  

Definitely number 1. There's no benefit in asking for an empty dataset. That would require a request, a database query and then a response. The first method simply clears the data that has already been confirmed to be deleted.

绝对数字1.要求空数据集没有任何好处。这需要一个请求,一个数据库查询,然后一个响应。第一种方法只是清除已经确认要删除的数据。