Bonjour,

Mon probléme est le suivant : je n'arrive pas a faire passer la variable array dans ma fonction jquery "change"...
Pourtant je l'ai bien avant avec mon log sur ma console javascript...

voila mon code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
 
        $(document).ready(function() {
            var $categorySelect = $('#categorySelect');
            var $categoryForm = $('#categoryForm');
            var $listPoints = $('#list-interest-points');
 
            var array = []
 
            // load categoryName(select) and InterestPoints(list)
            $.ajax({
                type: "GET",
                url: '/index_points_category/', 
                dataType: 'json',
                success: function(data) {
                    $.each(data, function(key,value) {
                        var categoryName = key;
                        var arrayPoints = value;
 
                        array[categoryName] = arrayPoints 
 
                        $categorySelect.append('<option value="'+ categoryName +'">'+ categoryName +'</option>');
                        $categoryForm.append('<option value="'+ categoryName +'">'+ categoryName +'</option>');
                    });
                }
            });    
 
            console.log(array);
 
            $categorySelect.on('change', function() {   
                var val = $(this).val(); 
                if(val != '') {                 
                //$listPoints.empty();
 
                    $.each(array, function(key,value) {
                        if (val == key){
                            $listPoints.append('<a href="#" class="list-group-item">'+value.name+'</a>');
                            console.log(value.name);
                        }
                    });
                }
            });
        });
Si quelqu'un peut m'aider, merci.

Cordialement