【问题标题】:Subscribe with parameters with Meteor-Angular使用 Meteor-Angular 订阅参数
【发布时间】:2015-12-20 11:11:16
【问题描述】:

我是 Meteor 的新手,我正在尝试使用 angular-meteor 构建在线报告应用程序,但在尝试使用 publishsubscribe 时遇到问题。

lib/collections.js 中,

TestReport = new Mongo.Collection('test_report');

server/publications.js 中,

Meteor.publish('testReportDetail', function(reportID) {
    check(reportID, String);

    return TestReport.findOne({_id: reportID});
});

client/test_report_detail.js

angular.module('myapp').controller('myCtrl', function($scope, $reactive, $stateParams) {
    $reactive(this).attach($scope);

    this.subscribe('testReportDetail', $stateParams.reportID);

    this.helpers({
        reportDetail: function() {
            return TestReport.find({_id: $stateParams.reportID});
        }
    });
});

当客户端浏览器尝试访问报告详细信息时,它会在控制台中收到错误

typeError: fn is not a function

任何想法...?

【问题讨论】:

    标签: javascript angularjs meteor angular-meteor


    【解决方案1】:

    在我刚刚发布的新 1.3.1 版本中修复了 this.subscribe,请再次检查 - https://github.com/Urigo/angular-meteor/releases

    【讨论】:

      【解决方案2】:

      server/publications.js 中,您应该使用 find() 而不是 findOne()。

      Meteor.publish('testReportDetail', function(reportID) {
          check(reportID, String);
      
          return TestReport.find({_id: reportID});
      });
      

      虽然这两个函数的签名相似,但它们返回的东西却大不相同! find() 将返回一个游标,但 findOne() 实际上返回一个对象。

      这是相关的documentation for Meteor.publish()

      另见documentation for Collections.find()

      【讨论】:

      • 感谢您的建议,但我已尝试用 find() 替换,但它仍然不起作用...还有其他想法吗?
      猜你喜欢
      • 2017-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多