使用Meteor 1.0,两个列表 - 通过 jQuery Sortable 连接 - 在将项目拖放到不同列表时正常工作。
除了从列表中拖动最后一个项目并将其放入新列表中的第一个或中间位置之外:
“排队任务中的异常:错误:无法执行'insertBefore' 'Node':要插入新节点的节点不是a 这个节点的孩子。“
将其删除为'last'有效。
我认为可能是Meteor的Blaze与jQuery冲突,但任何提示都非常受欢迎。控制台中的错误消息:
完整追踪:
at Error (native)
at DOMRange.attach (http://localhost:3000/packages/blaze.js?77…)
at DOMRange.setMembers (http://localhost:3000/packages/blaze.js?77…)
at DOMRange.removeMember (http://localhost:3000/packages/blaze.js?77…)
at http://localhost:3000/packages/blaze.js?77…
at Object.Tracker.nonreactive (http://localhost:3000/packages/tracker.js?19…)
at Object.eachView.stopHandle.ObserveSequence.observe.removedAt (http://localhost:3000/packages/blaze.js?77…)
at Object.cursor.observe.removedAt (http://localhost:3000/packages/observe-sequence.js?2f…)
at observeChangesCallbacks.removed (http://localhost:3000/packages/minimongo.js?9a…)
at Object.self.applyChange.removed (http://localhost:3000/packages/minimongo.js?9a…)
代码:
list_items.jade
ul.tasks.sortable
each tasks
|{{ >taskItem }}
else
|There are no tasks yet.
task_item.jade
template(name="taskItem")
li.task.item
.inner
.title
|{{ title }}
.date.light-text on {{ created }}
strong list: {{ listId }}
small rank: {{ rank }}
list_item.coffee
Template.listItem.helpers
'tasks': ->
currentUserId = Meteor.userId()
Tasks.find
userId: currentUserId
listId: this._id
,
sort:
rank: 1
Template.listItem.rendered = ->
@$(".tasks.sortable").sortable
placeholder: "task-placeholder"
connectWith: ".tasks.sortable"
tolerance: "pointer"
start: (e, ui) ->
item = ui.item
parent = ui.item.parent().get(0)
listId = Blaze.getData(parent)._id
newList = oldList = listId
return
stop: (e, ui) ->
el = ui.item.get(0)
parent = ui.item.parent().get(0)
listId = Blaze.getData(parent)._id
# Dragged within same list
if listId == oldList
console.log "same"
before = ui.item.prev().get(0)
after = ui.item.next().get(0)
if before
if after
newRank = (Blaze.getData(after).rank + Blaze.getData(before).rank) / 2
else
newRank = Blaze.getData(before).rank + 1
else if after
newRank = Blaze.getData(after).rank - 1
# Dragged to new list
else
console.log "*NEW*"
if Tasks.find({listId: listId}).count() == 0
newRank = 1
else
before = ui.item.prev().get(0)
after = ui.item.next().get(0)
if before
if after
newRank = (Blaze.getData(after).rank + Blaze.getData(before).rank) / 2
else
newRank = Blaze.getData(before).rank + 1
else if after
newRank = Blaze.getData(after).rank - 1
console.log "Moved " + Blaze.getData(el)._id + " from " + oldList + " to " + listId
#update the dragged Item's rank
Tasks.update
_id: Blaze.getData(el)._id
,
$set:
listId: listId
rank: newRank