大家好,我一直在尝试使用站点提供的 api 和 angularjs 中的 ng-repeat 功能对来自 openweathermap.org 的数据进行排序。出于某种原因,我似乎无法让它工作......我要做的是首先显示所有收集的数据,然后使用输入字段对其进行排序。
Javascript
var app = angular.module('weatherApp', []);
app.controller('weatherController', function($scope, $http) {
$http.jsonp('http://api.openweathermap.org/data/2.5/weather', { params : {
q : $scope.city,
units : $scope.units,
callback: 'JSON_CALLBACK',
APPID: $scope.id
}}).success(function(data){
$scope.data = data;
});
$scope.units = 'metric';
$scope.id = 'e08f9689f06c1b6eddb44396c749eb54';
$scope.reset = function(){
return $scope.city = "";
};
});
<div ng-app="weatherApp" ng-controller="weatherController">
<input ng-model="city.name" placeholder="City" />
<button ng-click="reset()">Reset</button>
<ul>
<li ng-repeat=" x in data | filter : city">
{{x.name}}
</li>
</ul>