2013-05-30 52 views
1

使用角度绑定真正有帮助,而不是jQuery来操纵DOM,但我不知道如何处理没有jQuery的拖动事件,例如,我想要拖动第二个框到第一个或拖动-repeat li更改订单角度js是否有拖动事件或拖动指令?

确实有角度拖动事件或指令?

<div> 
<li>This is first box</li> 
<li>This is second box</li> 
</div> 

//or like below 
<div><li ng-repeat="box in boxs | orderBy:'order'">{{box.name}}{{box.order}}</li></div> 
+0

你试过吗? http://angular-ui.github.io/ng-grid/ – finishingmove

+0

或者http://codef0rmer.github.io/angular-dragdrop/#/ – finishingmove

+0

你需要这个问题的更多帮助吗? –

回答

3

您可以

https://github.com/angular-ui/ui-sortable

包括您的文档中的文件sortable.js实现这一目标。 (请注意:jQuery和jQueryUI的额外依赖)

作为一个依赖添加排序模块到应用程序模块

var myAppModule = angular.module('MyApp', ['ui.sortable']) 

然后改变你的标记是这样的:

<ul ui-sortable="sortableOptions" ng-model="boxs"> 
    <li ng-repeat="box in boxs | orderBy:'order'"> 
     {{box.name}}{{box.order}} 
    </li> 
</ul> 

最后添加一些您的控制器中的“可排序”配置。

$scope.sortableOptions = { 
    update: function(e, ui) { 
     // do something when the sortorder has changed 
     // e.g. save the new order to your backend... 
    } 
};