数据
countries: [
{
id: 'qwe123rty456',
name: 'Australia',
regions: [
{
id: 'poi098uyt765',
name: 'Western Australia'
},
{
id: '123poi098qwe',
name: 'Queensland'
}
]
}
]
我可以通过以下方式获得特定国家/地区:
$scope.country = $meteor.object(Countries, $stateParams.countryId);
但我怎样才能获得特定区域?如:
{id: '123poi098qwe', name: 'Queensland'}
答案 0 :(得分:0)
$meteor.object
accepts only MongoDB objects似乎是第一个参数。您可以尝试循环结果以查找内部区域:
$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 core driver
获取您的MongoDb系列