我正在努力寻找一种方法将数据从两个(现在的)可排序列表保存到数据库。
$scope.dropTarget = null;
$scope.$watchCollection('lists[0].items', function() {
console.log('watch 0');
$scope.dropTarget = $scope.lists[0];
});
$scope.$watchCollection('lists[1].items', function() {
console.log('watch 1');
$scope.dropTarget = $scope.lists[1];
});
此代码我正在尝试另一个帖子Handling moving of item across lists in angular-ui sortable?
但是,我拥有的列表数量将根据用户创建的方式而变化。有没有办法在未知数量的项目上使用$ watchCollection?
是否有更好的方法可以将angular-ui可排序数据保存到mongo后端?那么移动到其他类别的项目会被保存吗?
由于
答案 0 :(得分:0)
你应该使用平等观察:
$scope.$watch('lists', function(newVal, oldVal){
console.log('changed');
}, true);
这会在列表中的某些内容发生变化时触发,即使它是例如:lists [0] .item.property