Reputation: 43
I have a 3 column display to mimick a kanban board. Each column does an ng-repeat on one $scope.list. I then filter each column to include the itmes I want. However now I want to be able drag an item from one column to another, and when dropping an item, perform a $http call to my rest api which will update that item.
I've looked at some tools like this - http://codef0rmer.github.io/angular-dragdrop/#/
But as far as I can tell this isn't any help to me as my data is all within one list.
The list that contains all the items is $scope.board and this it's JSON output.
{
"_id":"553b9fc4fee8d25ceeba6c92",
"boardAuthor":"553b9e64fee8d25ceeba6c91",
"title":"Board title",
"description":"Whatever",
"__v":0,
"boardTickits":[
{},
]
}
I thought one approach could be to split $scope.board into separate arrays but I can't seem to access the nested array.
for(i = 0; i < $scope.board.boardTickits.length; i++) {
if($scope.board.boardTickits.category == 1) {
$scope.todoCol = $scope.board.boardTickits[i];
} else if ($scope.board.boardTickits.category == 2) {
$scope.doingCol = $scope.board.boardTickits[i];
} else if($scope.board.boardTickits.category == 3) {
$scope.doneCol = $scope.board.boardTickits[i];
}
}
I get an error trying to get the length of the nested array.
If anybody provide some insight on accessing nested arrays that would be great, cheers!
Upvotes: 1
Views: 370
Reputation: 136154
Because you are doing .length
of undefined
object $scope.board.boardTickits
. You need to change you for
loop condition form $scope.board.boardTickits.length
to $scope.board.length
for(i = 0; i < $scope.board.length - 1; i++) {
if($scope.board.boardTickits.category == 1) {
$scope.todoCol = $scope.board.boardTickits[i];
} else if ($scope.board.boardTickits.category == 2) {
$scope.doingCol = $scope.board.boardTickits[i];
} else if($scope.board.boardTickits.category == 3) {
$scope.doneCol = $scope.board.boardTickits[i];
}
}
Upvotes: 1