首先,新年快樂。
但工作必須繼續! ;)AngularJS - 通過ID獲取數據
我得到了以下情況:
我得到了一些自定義標記爲靜態(非谷歌)地圖。我顯示(和過濾器),此代碼標記:
<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>
我它路線「經銷商-details.html」哪裏成功顯示ID:與此控制器/路由
<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": "[email protected]",
"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": "[email protected]",
"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';
}
非常感謝您!
只需迭代函數中的數組並返回具有正確標識的對象? –