How do you keep the DOM and the model in sync when using nested JQuery sortables? Say I have a Controller which is has defined as follows:
function testCtrl($scope) {
$scope.data = [{'name' : 'Test 1',
'index' : 0,
'values': [{'name' : 'sub test 1-1', 'index' : 0}, {'name' : 'sub test 1-2', 'index' : 1}]},
{'name' : 'Test 2',
'index' : 1,
'values': [{'name' : 'sub test 2-1', 'index' : 0}, {'name' : 'sub test 2-2', 'index' : 1}]}
];
$scope.orderProp = 'index';
}
Now I want to show the first level data and the second level data in JQuery sortables using the following template :
<ul ng-sortable='data'>
<li ng-repeat="d in data | orderBy:orderProp">
<p>{{d.name}}</p>
<ul ng-Sub-Sortable="d.values">
<li ng-repeat="sub in d.values">{{sub.eg}}</li>
</ul>
</li>
</ul>
And I use directives to specify the two different types of sortable lists as they do differ in behaviour (removed from below for brevity):
app.directive("ngSortable", function(){
return {
link: function(scope, element, attrs){
element.sortable();
}
};
}
app.directive("ngSubSortable", function(){
return {
link: function(scope, element, attrs){
element.sortable();
}
};
}
Now when the user sorts the list how do I update the model to ensure that the indexes are correct and therefore the lists are output correctly in the future?