【发布时间】:2018-05-29 10:19:26
【问题描述】:
我一直在尝试使用带有 angularjs 的 json 数据填充可搜索的下拉列表,我已经将 json 数据推送到服务器中,如果我使用 get 方法,我已经能够接收到来自服务器的响应。我没有确切地知道如何查询 json 数据并将它们填充到搜索栏中。 我已经附上了控制器脚本和 html
var app=angular.module('myapp',[]);
app.controller('myctrl',function($scope,$http){
$http({
method:"GET",
url:"http://localhost:5050/codes?val="}).then(function mySuccess(response){
$scope.msg=response.data;
},function myError(response){
$scope.msg=response.statusText;
});
});
<!DOCTYPE html>
信号
<body>
<div ng-app="myapp" ng-controller="myctrl" >
<select ng-model="search">
<option ng-repeat="names in msg " value="{{names.value}}"></option>
</select>
</div>
</body>
这是我从本地主机提供给页面的示例 json 数据 我必须用 json 数据的“值”部分填充搜索栏。
{"codes":
[{"code": "NSE/AHLWEST", "value": "Asian Hotels (West) Limited"},
{"code": "NSE/JINDALSWHL", "value": "Jindal South West Holding Limited"},
{"code": "NSE/WIPL", "value": "The Western India Plywoods Limited"},
{"code": "NSE/WSTCSTPAPR", "value": "West Coast Paper Mills Limited"}]
}
【问题讨论】:
-
您正在接收 JSON 作为对象,因此最好在您的
ng-repeat标签中使用msg.codes
标签: javascript jquery angularjs json ajax