Javascript 从methode http获取数组列表

Javascript 从methode http获取数组列表,javascript,jquery,angularjs,symfony,Javascript,Jquery,Angularjs,Symfony,我有一个工作类别的下拉列表。此列表在我打开页面时加载 当我选择一个类别时,会加载第二个下拉列表。该列表包含一个jobe title列表 当我选择一个职位时,我想像这样展示他的技能 每件事都很好,但问题是我如何才能把我的技能输入下拉列表。 这是我的代码: <script> var app = angular.module('myApp', []); var job_arr = {}; app.controller('customer

我有一个工作类别的下拉列表。此列表在我打开页面时加载

当我选择一个类别时,会加载第二个下拉列表。该列表包含一个jobe title列表

当我选择一个职位时,我想像这样展示他的技能

每件事都很好,但问题是我如何才能把我的技能输入下拉列表。 这是我的代码:

<script>
        var app = angular.module('myApp', []);
        var job_arr = {};
        app.controller('customersCtrl', function ($scope, $http) {
            $http.get("https://xxxxxxxxxxx-api./dev/profiles/categories/").then(function (response) {
                //console.log(response.data.Categories);
                $scope.myData = response.data.Categories;
                // console.log(response.data.Categories);
            });

            $scope.update = function () {
                $http.get("https://xxxxxxxxxxx-api./dev/profiles/categories/" + $scope.selectedCat).then(function (response) {
                    job_arr = response.data.profiles;
                    console.log(job_arr);
                    $scope.listOffer = response.data.profiles;
                    console.log(job_arr);
                });

                //$scope.listOffer = response.data.profiles;
                //get selected job title
                // console.log($scope.selectedJob);
                //console.log('ffffffffff :' + job_arr);
                var result = [];
                var i;
                var result;
                var html = '';
                for (i = 0; i < job_arr.length; ++i) {
                    if (job_arr[i]["JobTitle"] == $scope.selectedJob) {
                        //normalement  job_arr[i]["Skills"]
                        result = job_arr[i]["Skills"];
                        //console.log(result);
                        $.each(result, function (k, v) {
                            //alert(k + ' is ' + v);
                            html += "<option value =" + v + " >" + k + "<option>";
                        });

                        //$('#myskills').append(html);
                    }
                }
            };
            $scope.updatejob = function () {
                 alert('updatejob');
                $http.get("https://xxxxxxxxxxx-api./dev/profiles/categories/" + $scope.selectedCat).then(function (response) {
                    alert('updatejob');
                    job_arr = response.data.profiles;
                    console.log('eeeeeee:' + job_arr);

                });
            }
            $scope.mySwitch = false;
            $scope.switch = function () {
                // $(window).scrollTop(0);
                $('html, body').animate({scrollTop: 0}, 'slow');
                $scope.mySwitch = !$scope.mySwitch;


            };


        });

    </script>
及 “+$scope.selectedCat

{
    "profiles": [{
        "JobTitle": "DataScientist",
        "CategoryName": "Developper",
        "Salary": "100000",
        "Currency": "EUR",
        "Quantity": "12",
        "Searches": "423",
        "Skills": {
            "Java": "2",
            "Linux": "9",
            "OS X": "3",
            "Tableau": "32",
            "Windows": "4",
            "Math": "19",
            "AWS": "2",
            "Jira": "10"
        },
        "Interests": {
            "PcMag": "2",
            "LinuxMag": "3"
        }
    }, {
        "JobTitle": "System Administrator",
        "CategoryName": "Developper",
        "Salary": "100000",
        "Currency": "EUR",
        "Quantity": "12",
        "Searches": "423",
        "Skills": {
            "Linux": "123",
            "Réseau": "143"
        },
        "Interests": {
            "PcMag": "2",
            "LinuxMag": "3"
        }
    }, {
        "JobTitle": "Architect Cloud",
        "CategoryName": "Developper",
        "Salary": "100000",
        "Currency": "EUR",
        "Quantity": "2",
        "Searches": "1423",
        "Skills": {
            "Java": "1",
            "Linux": "90",
            "OS X": "10",
            "Windows": "4",
            "Réseau": "123",
            "AWS": "123",
            "Jira": "120"
        },
        "Interests": {
            "Amazon": "2",
            "Google": "4",
            "LinuxMag": "3"
        }
    }, {
        "JobTitle": "Architect SI",
        "CategoryName": "Developper",
        "Salary": "180000",
        "Currency": "EUR",
        "Quantity": "8",
        "Searches": "423",
        "Skills": {
            "Java": "2",
            "Linux": "9",
            "OS X": "3",
            "Tableau": "32",
            "Windows": "4",
            "Math": "19",
            "AWS": "2",
            "Jira": "10"
        },
        "Interests": {
            "PcMag": "2",
            "LinuxMag": "3"
        }
    }]
}

您正在寻找级联下拉选择

1-您应该使用id获取数据。这样profil就可以拥有类别的id

您可以在这里看到一个很好的示例,说明您想要实现的目标:

希望对您有所帮助

您可以尝试以下方法:

var-app=angular.module('myApp',[]);
应用程序控制器('myCtrl',函数($scope){
$scope.employees={
“概况”:[{
“职务名称”:“数据科学家”,
“CategoryName”:“开发者”,
“工资”:“100000”,
“货币”:“欧元”,
“数量”:“12”,
“搜索”:“423”,
“技能”:{
“Java”:“2”,
“Linux”:“9”,
“OS X”:“3”,
“画面”:“32”,
“窗口”:“4”,
“数学”:“19”,
“AWS”:“2”,
“吉拉”:“10”
},
“利益”:{
“PcMag”:“2”,
“LinuxMag”:“3”
}
}, {
“JobTitle”:“系统管理员”,
“类别名称”:“管理层”,
“工资”:“100000”,
“货币”:“欧元”,
“数量”:“12”,
“搜索”:“423”,
“技能”:{
“Linux”:“123”,
“Réseau”:“143”
},
“利益”:{
“PcMag”:“2”,
“LinuxMag”:“3”
}
}, {
“JobTitle”:“架构师云”,
“类别名称”:“建筑师”,
“工资”:“100000”,
“货币”:“欧元”,
“数量”:“2”,
“搜索”:“1423”,
“技能”:{
“Java”:“1”,
“Linux”:“90”,
“OS X”:“10”,
“窗口”:“4”,
“Réseau”:“123”,
“AWS”:“123”,
“吉拉”:“120”
},
“利益”:{
“亚马逊”:“2”,
“谷歌”:“4”,
“LinuxMag”:“3”
}
}, {
“职位名称”:“建筑师SI”,
“CategoryName”:“开发者”,
“工资”:“180000”,
“货币”:“欧元”,
“数量”:“8”,
“搜索”:“423”,
“技能”:{
“Java”:“2”,
“Linux”:“9”,
“OS X”:“3”,
“画面”:“32”,
“窗口”:“4”,
“数学”:“19”,
“AWS”:“2”,
“吉拉”:“10”
},
“利益”:{
“PcMag”:“2”,
“LinuxMag”:“3”
}
}]
};
});

选择类别


选择职务

选择技能

类别:{categoryObj.CategoryName}
职务:{{jobTitleObj.JobTitle}}
技能:{{skill}}

谢谢您的回答。但我想直接从url获取数据,它是动态的!@AitFrihaZaid您需要为此编写一个服务,您可以将其保存在scope变量中。。
{
    "Categories": [
         {
            "CategoryName":"Marketing"
        },   {
            "CategoryName":"Developper"
        },   {
            "CategoryName":"Management"
        }       ]
}
{
    "profiles": [{
        "JobTitle": "DataScientist",
        "CategoryName": "Developper",
        "Salary": "100000",
        "Currency": "EUR",
        "Quantity": "12",
        "Searches": "423",
        "Skills": {
            "Java": "2",
            "Linux": "9",
            "OS X": "3",
            "Tableau": "32",
            "Windows": "4",
            "Math": "19",
            "AWS": "2",
            "Jira": "10"
        },
        "Interests": {
            "PcMag": "2",
            "LinuxMag": "3"
        }
    }, {
        "JobTitle": "System Administrator",
        "CategoryName": "Developper",
        "Salary": "100000",
        "Currency": "EUR",
        "Quantity": "12",
        "Searches": "423",
        "Skills": {
            "Linux": "123",
            "Réseau": "143"
        },
        "Interests": {
            "PcMag": "2",
            "LinuxMag": "3"
        }
    }, {
        "JobTitle": "Architect Cloud",
        "CategoryName": "Developper",
        "Salary": "100000",
        "Currency": "EUR",
        "Quantity": "2",
        "Searches": "1423",
        "Skills": {
            "Java": "1",
            "Linux": "90",
            "OS X": "10",
            "Windows": "4",
            "Réseau": "123",
            "AWS": "123",
            "Jira": "120"
        },
        "Interests": {
            "Amazon": "2",
            "Google": "4",
            "LinuxMag": "3"
        }
    }, {
        "JobTitle": "Architect SI",
        "CategoryName": "Developper",
        "Salary": "180000",
        "Currency": "EUR",
        "Quantity": "8",
        "Searches": "423",
        "Skills": {
            "Java": "2",
            "Linux": "9",
            "OS X": "3",
            "Tableau": "32",
            "Windows": "4",
            "Math": "19",
            "AWS": "2",
            "Jira": "10"
        },
        "Interests": {
            "PcMag": "2",
            "LinuxMag": "3"
        }
    }]
}