我正在尝试对卡片进行重新排列,例如Trello。
我在How does Trello handle rearrangement of cards,lists,checklists etc和What does the POS actually mean in the Trello API处了解了它的工作方式
每个位置均以65,535开头,并以最后一个位置+ 65,535创建新的卡片或列表,例如:
卡列表
{ "_id" : ObjectId("5e7ea117e13673ec0db43104"),"name" : "A","position" : 65.535 }
{ "_id" : ObjectId("5e7ea117e13673ec0db43105"),"name" : "B","position" : 131.071 }
{ "_id" : ObjectId("5e7ea117e13673ec0db43106"),"name" : "C","position" : 196.607 }
{ "_id" : ObjectId("5e7ea117e13673ec0db43107"),"name" : "D","position" : 262.143 }
{ "_id" : ObjectId("5e7ea117e13673ec0db43108"),"name" : "E","position" : 327.679 }
如果卡片E插入卡片A的顶部,它将被2除(65,535 / 2 = 32,767)
如果卡片A插入卡片E的底部,则其总和为65,535(327,679 + 65,535 = 393,214)
在中间,两个相邻位置的位置平均值。
问题是,如何将任何位置更改为倒数第二个位置?在D和E之间?还是在A和B之间?
如果将卡A插入卡D和E之间,或者将卡E插入A和B之间,这是什么逻辑?
有更好的方法吗?