数据
countries: [
{
id: 'qwe123rty456',
name: 'Australia',
regions: [
{
id: 'poi098uyt765',
name: 'Western Australia'
},
{
id: '123poi098qwe',
name: 'Queensland'
}
]
}
]I可以使用以下内容获得特定国家:
$scope.country = $meteor.object(Countries, $stateParams.countryId);但是我如何才能得到一个特定的区域呢?例如:
{id: '123poi098qwe', name: 'Queensland'}发布于 2015-11-22 15:16:13
$meteor.object 只接受MongoDB对象似乎是第一个参数。您可以尝试循环结果以找到内部区域,如下所示:
$scope.country = $meteor.object(Countries, $stateParams.countryId);
$scope.objectFindByKey(array, key, value) {
for (var i = 0; i < array.length; i++) {
if (array[i][key] === value) {
return array[i];
}
}
return null;
}
$scope.region = $scope.objectFindByKey($scope.country["regions"], "id", "your_id");或者尝试使用Meteor的MongoDb 核心驱动器来获取您的核心驱动器集合
https://stackoverflow.com/questions/33856199
复制相似问题