Javascript 如何将不同数组中的多个值添加到下拉列表中?
我试图将api中的数据显示在下拉列表中(部门全名)。我可以显示一个值,但不能显示多个值。你能告诉我哪里出了问题吗 从json数组中,我想在select下拉列表中获取值。我想进入下拉列表的值是shortName、Serm和section。我只能显示shortName,但不能显示其他2个值 index.controller.jsJavascript 如何将不同数组中的多个值添加到下拉列表中?,javascript,angularjs,dropdown,Javascript,Angularjs,Dropdown,我试图将api中的数据显示在下拉列表中(部门全名)。我可以显示一个值,但不能显示多个值。你能告诉我哪里出了问题吗 从json数组中,我想在select下拉列表中获取值。我想进入下拉列表的值是shortName、Serm和section。我只能显示shortName,但不能显示其他2个值 index.controller.js $http.get('https://student.herokuapp.com/department/') .success(function(re
$http.get('https://student.herokuapp.com/department/')
.success(function(response){
$scope.deptDetails=response.department;
// console.log($scope.deptDetails);
deptLen=response.department.sections.length;
console.log(deptLen);
for(var i=0;i<deptLen;i++){
$scope.deptDetails.push({"_id":response.department._id,
"shortName":response.department.shortName,
"section":response.department.sections[i].section,
"semester":response.department.sections[i].semester});
}
});
这是你能做到的
app.controller("dobController", ["$scope", '$http',
function($scope, $http) {
$scope.displayValues = [];
$http.get('test.json').then(function(response){
$scope.data = response.data;
console.log(response.data.department);
$scope.displayValues.push(response.data.department.shortName);
response.data.department.sections.forEach(function(key){
$scope.displayValues.push(key.section);
$scope.displayValues.push(key.semester);
})
});
}
]);
编辑
response.data.department.sections.forEach(function(key){
$scope.displayValues.push(response.data.department.shortName + " "+ key.section + " "+key.semester);
})
你可以这样做
app.controller("dobController", ["$scope", '$http',
function($scope, $http) {
$scope.displayValues = [];
$http.get('test.json').then(function(response){
$scope.data = response.data;
console.log(response.data.department);
$scope.displayValues.push(response.data.department.shortName);
response.data.department.sections.forEach(function(key){
$scope.displayValues.push(key.section);
$scope.displayValues.push(key.semester);
})
});
}
]);
编辑
response.data.department.sections.forEach(function(key){
$scope.displayValues.push(response.data.department.shortName + " "+ key.section + " "+key.semester);
})
在你的弹夹中,你指的是哪个下拉菜单?@Sajeetharan哦,对不起。我指的是部门全名。在你的plunker中,你指的是哪个下拉菜单?@Sajeetharan哦,对不起。我指的是部门全名。嘿,谢谢你的努力。如何像CS C一样在一行中打印4@HebleV检查这张选票。这就是我读了这个问题后的想法。@HebleV它有帮助吗?@Sajeetharan我看到它的工作plnkr,但当我把它包括进来时,它没有显示出来。它也没有给出任何错误。感谢你的努力。如何像CS C一样在一行中打印4@HebleV检查这张选票。这就是我在阅读问题后的想法。@HebleV它有帮助吗?@Sajeetharan我看到它的工作plnkr,但当我包含它时,它没有显示。它也没有给出任何错误