更新事物列表,而无需点击所有条目 [英] Update a list of things without hitting every entry

查看:101
本文介绍了更新事物列表,而无需点击所有条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在数据库中有一个用户可以订购的列表.

I have a list in a database that the user should be able to order.

itemname|  order value (int)
--------+---------------------         
salad   |  1
mango   |  2
orange  |  3
apples  |  4

从数据库加载时,我只是order by order_value.

On load from the database, I simply order by order_value.

通过拖放,他应该可以移动apples,使其出现在列表的顶部.

By drag 'n drop, he should be able to move apples so that it appears at the top of the list..

itemname|  order value (int)
--------+---------------------         
apples  |  4
salad   |  1
mango   |  2
orange  |  3

好的.因此,现在在内部,我必须更新每个列表项!如果列表包含20或100个项目,那么对于简单的拖动操作来说,这是很多更新.

Ok. So now internally I have to update EVERY LIST ITEM! If the list has 20 or 100 items, that's a lot of updates for a simple drag operation.

itemname|  order value (int)
--------+---------------------         
apples  |  1
salad   |  2
mango   |  3
orange  |  4

我只希望进行一次更新.我想到的一种方法是,内部订单"是否为double值.

I'd rather do it with only one update. One way I thought of is if "internal Order" is a double value.

itemname|  order value (double)
--------+---------------------         
salad   |  1.0
mango   |  2.0
orange  |  3.0
apples  |  4.0

在执行拖放n'操作之后,我指定apples的值小于它出现在以下项之前的值:

SO after the drag n' drop operation, I assign apples has a value that is less than the item it is to appear in front of:

itemname|  order value (double)
--------+---------------------         
apples  |  0.5
salad   |  1.0
mango   |  2.0
orange  |  3.0

..如果将某个项目拖到中间的某处,则它的order_value大于它在..之后出现的项目.在这里,我将orange移到了saladmango之间:

.. and if an item is dragged into the middle somewhere, its order_value is bigger than the one it appears after .. here I moved orange to be between salad and mango:

itemname|  order value (double)
--------+---------------------         
apples  |  0.5
salad   |  1.0
orange  |  1.5
mango   |  2.0

有什么更好的方法吗?

推荐答案

我最终使用了

I ended up using an adjacencies table. I didn't know about it at the time.

这篇关于更新事物列表,而无需点击所有条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆