我有一个这样的集合:(许多国家,每个国家都包含许多地区)
countries: [
{
id: 'qwe123rty456',
name: 'Australia',
regions: [
{
id: 'poi098uyt765',
name: 'Western Australia'
},
{
id: '123poi098qwe',
name: 'Queensland'
}
]
}
]
使用铁路由器然后设置几条路线,这些路线适用于'国家'
app.js
Countries = new Mongo.Collection('countries');
if (Meteor.isClient) {
angular.module('geo',['angular-meteor', 'ui.router']);
angular.module('geo').config(function($urlRouterProvider, $stateProvider, $locationProvider){
$locationProvider.html5Mode(true);
$stateProvider
.state('countries', {
url: '/countries',
templateUrl: 'countries.html',
controller: 'countries_controller'
})
.state('country', {
url: '/countries/:countryId',
templateUrl: 'country.html',
controller: 'country_controller'
})
.state('region', {
url: '/countries/:countryId/regions/:regionId',
templateUrl: 'region.html',
controller: 'country_controller'
});
$urlRouterProvider.otherwise("/countries");
});
angular.module('geo').controller('countries_controller', ['$scope', '$meteor', '$state',
function ($scope, $meteor, $state) {
$scope.countries = $meteor.collection(function() {
return Countries.find({})
});
}]);
angular.module('geo').controller('country_controller', function($scope, $meteor, $stateParams) {
$scope.country = $meteor.object(Countries, $stateParams.countryId);
});
}
我可以在countries.html中显示国家/地区列表,并使用' countries /:countryId'将每个国家/地区链接到自己的country.html页面。路由。
countries.html
<ul>
<li ng-repeat="country in countries">
<span>{{country.name}}</span>
<a href="/countries/{{country._id}}">View</a>
<span>Regions:</span>
<ul>
<li ng-repeat="region in country.regions">
<span>{{region.name}}</span>
<a href="countries/{{country._id}}/regions/{{region._id}}">View</a>
</li>
</ul>
</li>
</ul>
现在,我想在每个区域内显示自己的区域内的&#39;使用&#39; / countries /:countryId / regions /:regionId&#39;的页面路线,但这不起作用,不知道我需要做什么。
region.html
{{region.name}}