gpt4 book ai didi

angularjs - angular-meteor 根据参数查找 MongoDb 集合并返回

转载 作者:IT老高 更新时间:2023-10-28 13:22:06 24 4
gpt4 key购买 nike

我正在尝试使用 Meteor 和 Angular.js 的组合在我的 MongoDb 中获取某个地址的警告

在我的html文件中,我正在做

<div ng-controller = "myController as myCtrl">
{{myCtrl.warnings}}
{{myCtrl.getWarnings("123 Test Street, TestCity, TestState")}}
</div>

在我的 app.js 文件中:

Warnings = new Mongo.Collection("Warnings");

if (Meteor.isClient) {
var app = angular.module('ffprototype', [ 'angular-meteor' ]);

app.controller('myController', ['$window','$meteor', function($window, $meteor) {

this.warnings = $meteor.collection(Warnings);

this.getWarnings = function(findByAddress){
Warnings.find({address: findByAddress}).fetch();
}
}]);
}

我的 mongoDb 集合:

{
"_id": "3ixgxEMZDWGtugxA7",
"address": "123 Test Street, TestCity, TestState",
"warning": "Warning 1"
}
{
"_id": "HZH5FvCD5driBYSJz",
"address": "123 Test Street, TestCity, TestState",
"warning": "Warning 2"
}

html 网页的输出显示了整个警告集合(感谢 {{currentDispatch.warnings}},但对于 {{currentDispatch.getWarnings("123 Test Street , TestCity, TestState")}}

最佳答案

您应该使用 $meteor.object为此

this.getWarnings = function(findByAddress){
$meteor.object(Warnings, { address: findByAddress }, false); // passing false here to not update the collection from changes in the client
}

关于angularjs - angular-meteor 根据参数查找 MongoDb 集合并返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30140736/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com