Picklist(多选)组件不会更新数据。 BootStrap组件+ AngularJS

时间:2016-01-13 12:22:20

标签: javascript angularjs

我有一个基于JSP + AngularJS的项目。

在我的jsp中,我有一个由引导程序模板提供的选项列表组件。我从我的数据库接收数据,我需要与之合作的公司名称,但我仍然不能将我选择的数据“传递”到所选择的那些。 检查图片以了解。任何信息都有帮助。感谢。

enter image description here

我的AngularJS控制器:

BoxApp.controller("CadastroCertificadoController", function($scope,     $http) {

$scope.clientes = {};


$scope.iniciar = function() {
$http.get('/boxmlV2/cadastrocertificado').success(function(response) {
    $scope.clientes = response;
});
};

$scope.iniciar();

});

我的jsp页面中的组件:

                               <div class="form-group">
                                    <label class="control-label col-md-3">Empresas:</label>
                                    <div class="col-md-9">
                                    <select ng-model="certificadoIncluirAlterar.razaoSocial" multiple="multiple" class="multi-select"
                                            id="my_multi_select1" name="my_multi_select1[]">
                                            <option ng-repeat="c in clientes" value="{{c.idCliente}}">{{c.razaoSocial}}</option>
                                    </select>

                                    </div>
                                </div>

我的java控制器(只需从我的数据库填充上一张表中的数据)

@Controller
public class CadastroCertificadoController {

@Autowired
private ClienteService clienteService;

@RequestMapping(value = "/cadastrocertificado", method = RequestMethod.GET)
public ModelAndView iniciar(ModelMap modelMap) {
    return new ModelAndView("cadastrocertificado");
}

@RequestMapping(value="/cadastrocertificado", method=RequestMethod.GET, produces={"application/json"})
public @ResponseBody List<ClienteDTO> obterTodos(ModelMap modelMap){
    return clienteService.obterTodos();
}


}

1 个答案:

答案 0 :(得分:0)

完成。

这就是我的组件的样子:

                                      <div class="form-group">
                                        <label class="control-label col-md-3">Empresas:</label>
                                        <div class="col-md-9">

                                            <select  multiple="multiple" class="multi-select" id="my_multi_select1" name="my_multi_select1[]">
                                                <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>

这是我的AngularJS控制器:

BoxApp.controller("CadastroCertificadoController", function($scope, $http) {

$scope.clientes = {};

$scope.iniciar = function() {
    $http.get('/boxmlV2/cadastrocertificado').success(function(response) {
        $scope.clientes = response;
    });
};

$scope.iniciar();

$scope.clientes2 = [];

$scope.atribuirUm = function(index, c) {
    $scope.clientes2.push(c);
    $scope.clientes.splice(index, 1)
}    

$scope.limparUm = function(index, c2) {
    $scope.clientes2.splice(index, 1)
    $scope.clientes.push(c2);
}
});

enter image description here