我在使用角度时遇到问题:
http://jsfiddle.net/EpxHE/14/light/
这是我做的:
指示:
.directive("myDirective", function () {
return {
restrict: "A",
replace: true,
compile: function (element, attrs) {
var $newDiv = $("<div class='dragdiv'>4</div>");
makeElementAsDragAndDrop($newDiv);
element.html($newDiv);
}
}
})
function makeElementAsDragAndDrop(elem) {
$(elem).draggable({
snap: '#droppable',
snapMode: 'outer',
revert: "invalid",
cursor: "move",
helper: "clone"
});
$(elem).droppable({
drop: function(event, ui) {
var $dragElem = $(ui.draggable).clone().replaceAll(this);
$(this).replaceAll(ui.draggable);
makeElementAsDragAndDrop(this);
makeElementAsDragAndDrop($dragElem);
}
});
}
HTML:
<div my-directive ng-repeat="item in items"></div>
我认为问题在于 makeElementAsDragAndDrop() 函数仅在创建元素之前调用一次。你有解决方案吗 ?谢谢