我遇到了以下情况:
我有一些自定义标记和静态(非谷歌)地图。我使用以下代码显示(和过滤)标记:
<div ng-controller="DealerDetailsListCtrl">
<a ng-click="showdetails=!showdetails" href="#/dealer/{{marker.id}}" class="marker" style="left:{{marker.left}};top:{{marker.top}}" ng-repeat="marker in dealer|zipFilter:zipCodeLookup:countryLookup"></a>
</div>
我将其路由到成功显示 ID 的“dealer-details.html”:
<div class="alldealermodal" ng-controller="DealerDetailsCtrl">
<div ng-view></div>
</div>
使用此控制器/路由:
app.config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/dealer/:id', {templateUrl: 'files/tpl/dealer-details.html', controller: DealerDetailsCtrl}).
otherwise({redirectTo: '/'});
}]);
和
function DealerDetailsCtrl($scope, $routeParams) {
$scope.id = $routeParams.id;
}
由于我对 angularJS 很陌生,我想知道,如何通过 ID 获取所有数据。
我的 json 文件如下所示:
[
{
"id": "2",
"name": "Laden Dortmund",
"strasse": "Unionstr.",
"hausnr": 1,
"plz": "45525",
"stadt": "Dortmund",
"land": "DE",
"url": "http://www.google.de",
"tel": "0234-234568",
"email": "lade@indortmund.de",
"left": "200px",
"top": "300px",
"lowRange":60000,
"highRange":70000
},
{
"id": "1",
"name": "Laden Unna",
"strasse": "Berlinerstr.",
"hausnr": 134,
"plz": "78654",
"stadt": "Unna",
"land": "AT",
"url": "http://www.bing.de",
"tel": "0234-11223344",
"email": "lade@inunna.de",
"left": "250px",
"top": "500px",
"lowRange":40000,
"highRange":50000
}
]
依此类推....我想从所选ID中获取所有数据。我怎样才能做到这一点?有人能给我一个提示吗?
我使用这个控制器从 json 中获取所有数据:
function DealerListCtrl($scope, $http) {
$scope.dealer = [];
$http.get('files/js/dealer.json').success(function(data) {
$scope.dealerall = data;
});
$scope.orderProp = 'id';
}