我在这里使用了Avital的例子:https://github.com/meteor/meteor/tree/master/examples/unfinished/reorderable-list
出于某种原因,在我的实现中,我需要重新加载页面才能使其工作。换句话说,一旦我的应用程序加载到浏览器中,该列表就不可排序。然后我刷新浏览器页面,一切都很好。
我的实施:
在客户端上,我调用服务器方法来设置列表中每个项目的初始排名。注意,我也尝试在Meteor.startup内的服务器上运行Meteor.call,结果相同:
Meteor.call("setInitialTodosRank")
我添加了可排序代码(来自Avital&#39>
UI.Body.Rendered = ->
# uses the 'sortable' interaction from jquery ui
$('.list-group').sortable stop: (event, ui) -> # fired when an item is dropped
el = ui.item.get(0)
before = ui.item.prev().get(0)
after = ui.item.next().get(0)
newRank = undefined
unless before # moving to the top of the list
newRank = SimpleRationalRanks.beforeFirst(UI.getElementData(after).rank)
else unless after # moving to the bottom of the list
newRank = SimpleRationalRanks.afterLast(UI.getElementData(before).rank)
else
newRank = SimpleRationalRanks.between(UI.getElementData(before).rank, UI.getElementData(after).rank)
console.log "newrank is #{newRank}."
Todos.update UI.getElementData(el)._id,
$set:
rank: newRank
使用的软件包:Iron Router,jquery-ui-sortable,hammer,blaze-layout和iron-router-active。