0
It can be in jquery or Angularjs help.
I have the following picklist (done in hand):
<div class="form group">
<label class="control-label col-md-3">Selecionar Empresas:</label>
<select id="select1" name="select1" multiple="multiple">
<option ng-repeat="c in clientes" value="{{c.idCliente}}" ng-click="atribuirUm($index, c)">{{c.razaoSocial}}</option>
</select>
<select ng-model="listaEmpresas" id="select2" name="select2" multiple="multiple">
<option selected="selected" ng-repeat="c2 in clientes2" value="{{c2.idCliente}}" ng-click="limparUm($index, c2)">{{c2.razaoSocial}}</option>
</select>
</div>
Before, I only needed the value in clientes2 to work the data at other times.
Now, I need to maintain the status of the first select and the second, every time I load the page, I need to know what was left on the right and left.
How can I with this code, adapt this? Any info is valid, thank you !
/**
* 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);
};
Create a new element and copy the values to it. Have you tried this? See: https://docs.angularjs.org/api/ng/function/angular.copy
– celsomtrindade
Another tip: It will be a temptation, but if you are using Angularjs, avoid going to jQuery the most. At first I always tried to solve with jQuery, especially because I was faithful user of it, but today I realize that it is not necessary to use it.
– celsomtrindade
Celsom, but when I refresh the page, there are no values I saved. Got it, thanks.
– Leonardo Leonardo
Ai you need to do some kind of storage, either in bank or in cache. But this is relative.. depends on your flow. In some cases, it is not even allowed to cache, only if it is in your database.. But it will depend on your flow.
– celsomtrindade
Because it is in the client, you can pass by query string or save in cookie.
– PauloHDSousa