0
using: https://code.google.com/archive/p/jquery-ui-picklist/
I can’t load data from my client table into the picklist. It was already working on another template, changed the template in the company and I’m adapting to new components. I took this picklist out because the template doesn’t have.
What could be wrong? I have no idea, just don’t load anything into the picklist.
angular.module('BoxApp').controller("CadastroCertificado", function($scope, $http) {
$scope.clientes = {};
$scope.listaEmpresas = [];
$scope.iniciar = function() {
$http.get(urlRestServer + '/cadastrocertificado').success(function(response) {
$scope.clientes = response;
});
};
$scope.iniciar();
/**
* Trabalhando o componente picklist
*/
$scope.clientes2 = [];
$scope.atribuirUm = function(index, c) {
var cliente = {};
cliente.idCliente = c.idCliente;
cliente.razaoSocial = c.razaoSocial;
$scope.clientes2.push(cliente);
$scope.clientes.splice(index, 1);
};
$scope.limparUm = function(index, c2) {
$scope.clientes2.splice(index, 1);
$scope.clientes.push(c2);
};
/**
* Trecho para validar o form ao submeter.
*/
$scope.submitted = false;
$scope.submitForm = function(form, clientes2) {
$scope.listaEmpresas = $scope.clientes2;
$scope.submitted = true;
if (form.$valid) {
$scope.cadastraCertificado();
}
};
/**
* Requisição POST (ajax)
*/
$scope.cadastraCertificado = function() {
var dados = {
urlCertificado : $scope.certificadoIncluirAlterar.urlCertificado,
strDataValidadeCertificado : $scope.certificadoIncluirAlterar.strDataValidadeCertificado.toString(),
senhaCertificado : $scope.certificadoIncluirAlterar.senhaCertificado,
listaEmpresas : $scope.listaEmpresas
};
$http.post(urlRestServer + '/cadastrocertificado/salvarCertificado', dados).then(function(response) {
}, function(response) {
$scope.sucesso();
});
};
$scope.sucesso = function() {
$scope.closeModal();
$scope.iniciar();
};
$scope.closeModal = function() {
$('#myModal').modal('hide');
};
});
<div class="form-group">
<label class="control-label col-md-3">Empresas:</label>
<div class="col-md-9">
<select id="foobar" name="foobar" multiple="multiple">
<option ng-repeat="c in clientes" value="{{c.idCliente}}" ng-click="atribuirUm($index, c)">{{c.razaoSocial}}</option>
<option selected ng-repeat="c2 in clientes2" value="{{c2.idCliente}}" ng-click="limparUm($index, c2)">{{c2.razaoSocial}}</option>
</select>
</div>
</div>
Celsom, I’m working with Sponse on the screen where I fill a grid, I work with ng-repeat on top of customers, like you said. Already in select, I also work, with ng-repeat also on top of clients, where my Answer was, I created a function to assign the q was selected to the list of the right and vice versa, but neither click on it customers. I wouldn’t use ng-repeat here? Because the component is in jquery but my app is all angular.
– Leonardo Leonardo
Yes, but first you need to have the values, right? In your role
$scope.iniciar = function()
probably you are not capturing the data correctly, as stated in the reply. Try to change the treatment as reported in the reply. ng-repeat will only be used later, after assigning the data.– celsomtrindade
Celsom, the return that is in Respose, are 20 client objects of the base. The values are being stored in 'clients'. Need to fix something here if the values are coming ok? I do not understand how I need to fix based on the answer.
– Leonardo Leonardo
'Cause this way it worked before, I just changed the component.
– Leonardo Leonardo
If you put
console.log(response)
before$scope.clientes = response;
what appears on the console?– celsomtrindade