使用Ng的Ui Sortable和Angular JS嵌套列表 - 重复

时间:2015-04-10 12:58:45

标签: angularjs jquery-ui

我在todos(todo.tasks)中设置了todos($ scope.todos)和嵌套任务的firebase:

...todo1
 .....task1
 .....task2
 .....task3
...todo2
 .....task1
 .....task2
 .....task3
etc.

我能够使用ui.sortable对todos进行排序,然后访问$ scope.todos.indexOf(todo)以获取todos数组的顺序,然后更改firebase中数组的优先级,以便我重新加载页面,订单将正确加载。 (注意:todos显示为ng-repeat =" todo in todos"

但是,在每个待办事项中,我都有通过ng-repeat ="(任务,密钥)在todo"中访问的任务。我也希望能够对这些进行排序,但是我无法在todo.tasks中访问正确的任务索引。

我对todo和on(任务,密钥)上的ui.sortable使用相同的ui-sortable选项。我在尝试传递ng-model =" todo.tasks"时收到错误。进入ui.sortable的任务。如果没有这个ng-model工作,indexOf值就不会 似乎要更新。如果我不在ng-repeat中使用模型,我可以在屏幕上移动项目但是indexOf(任务)值不显示更新?有什么想法吗?

我可以为此提供更多信息,但是还不想让这个问题陷入困境。谢谢你们和他们任何洞察力的加尔斯!

JS

     $scope.sortableOptions = {
       stop: function(event, ui) {

    //Updates priority of todos
        $scope.todos.forEach(function(todo){
        todo.priority = $scope.todos.indexOf(todo)
        $scope.todos.$save(todo)
    }); 

    // not recieving proper index value because I get an error passing ng-model in 
    // but update will look similar to this


     var todID = $scope.todos[ui.item.scope().$parent.$index].$id;


     $scope.tasks = fbutil.syncArray('users/' + user.uid + '/todos/' + todID +'/tasks'); //simply pulling an $firebase array

     $scope.tasks.$loaded().then(function(){

       $scope.tasks.forEach(function(task){

         task.priority = $scope.tasks.indexOf(task)
         $scope.tasks.$save(task)


       })
     })

HTML

    <div class="row" ng-model = "todos" ui-sortable="sortableOptions">
      <div class="input-group" ng-repeat = "todo in todos"  >
            {{todo.simpleDesc}}

                <div class="row"  ui-sortable="sortableOptions"  ng-model ="todo">
                   <div id="allTasks" class="input-group" ng-repeat="(task,key) in todo.tasks"  >
                     {{key.item}} 
             </div>
         </div>
      </div>
    </div>
移动任务项时出现

错误: TypeError:undefined不是函数     在sortable.js:249     在Scope。$ eval(angular.js:14466)     在Scope。$ apply(angular.js:14565)     在callbacks.stop(sortable.js:246)     在HTMLDivElement。 (sortable.js:25)

0 个答案:

没有答案