【发布时间】:2016-08-04 04:45:23
【问题描述】:
我正在使用可排序的 angular ui 在列表之间拖放项目。我想要做的是(在某些拖放条件下)有一个确认对话框,如果用户取消对话框,则将列表恢复为原始状态。我可以在更新事件中使用ui.item.sortable.cancel() 方法,但是如果我使用返回承诺的模式,我无法弄清楚如何在取消时恢复列表。这是我的控制器中的内容(modalService 是一个引导程序 $uibModal):
$scope.sortableOptions =
handle: ' > span > span > .task-drag-icon',
connectWith: ".task-subset"
placeholder: "sortable-placeholder",
forcePlaceholderSize: true,
update: (e, ui) ->
if ui.item.sortable.sourceModel == ui.item.sortable.droptargetModel #sort was within the same list
#some other logic here.....
else
droptarget_element = ui.item.sortable.droptarget
if droptarget_element.attr('ng-model') == "task.subTasks"
#need the user to confirm here if they really want to do this drag/drop
modalOptions =
closeButtonText: 'Cancel'
actionButtonText: 'Make SubTask'
headerText: 'Make SubTask?'
bodyText: 'This action will remove any existing task groups as it will become a child task. Is this OK?'
modalService.showModal({}, modalOptions).then (result) ->
console.log "accpted"
, () ->
console.log "cancelled"
#need to call ui.item.sortable.cancel() here, but I cant because the update callback has finished already!!!!
console.log "finished - gets to here immediately as modalService is asyncronous"
return
任何建议表示赞赏。
【问题讨论】:
标签: angularjs bootstrap-modal jquery-ui-sortable angular-ui-sortable