I'm new to JavaScript, and I'm using a framework Restart written with AngularJs for HTTPS requests. I'm having a lot of trouble initializing a literal object, with the following structure:
$scope.niveisDeAcesso = [
{nivel:"LISTAR", selected: false},
{nivel:"ADICIONAR", selected: false},
{nivel:"EDITAR", selected: false},
{nivel:"EXCLUIR", selected: false}
];
In this section I initialized an object:
$scope.perfilDeAcesso = {};
Here I initialized an array within my object:
$scope.perfilDeAcesso.itensPerfilDeAcesso = [];
The structure of my object in the end should be more or less this:
perfilDeAcesso = {itensPerfilDeAcesso[]}
and itemsProfileProcess should have a structure similar to:
itemPerfilDeAcesso = { itemDeAcesso: {...}, niveisDeAcesso: [...]}
My problem
Can not set property xxx of undefined
This is to initialize the itensPerfilDeAcesso
so that I can receive the itemDeAcesso
:
Restangular.all('itemdeacesso').getList().then(function(itens) {
for (var int = 0; int < itens.length; int++) {
$scope.perfilDeAcesso.itensPerfilDeAcesso[int].itemDeAcess =
UtilService.limparDados(itens[int]);
$scope.perfilDeAcesso.itensPerfilDeAcesso[int].niveisDeAcesso =
angular.copy($scope.niveisDeAcesso);
}
})