【问题标题】:Issue with meteorJS object publishing流星JS对象发布问题
【发布时间】:2015-06-19 15:31:17
【问题描述】:

我的 jQuery 插件发布数据时遇到问题。该插件是自动添加包,定义如下:

Products.attachSchema(new SimpleSchema({

  tooteNimetus:  {
    type: String,
    optional: true,
    autoform: {
      type: "selectize",
      options: function () {
        return productList
      }
    }

我需要定义这个产品列表。

当我将它定义为一个对象时:

productList = [{label: "AXPK Plus 4G60", value: 2001244}]

,效果很好

但是我需要从集合中获取productList,所以我这样定义它:

ProductMap = new Mongo.Collection("productMap");

ProductMap.attachSchema(new SimpleSchema({
    label: {
        type: String,
        label: "Toote nimetus"
    },
    value: {
        type: Number,
        label: "Toote kood"
    },
    miinimumTakistus: {
        type: Number,
        label: "Toote miinimum takistus",
        decimal: true
    }
}));

productList = ProductMap.find({}).fetch();

还有我的订阅和发布: 在我的 /server 中:

Meteor.publish("productMap", function () {
    return ProductMap.find({});
});

lib/router 中的子目录:

Router.map(function () {
    this.route('insert', {
        path: '/insert',
        template: 'insertProduct',
        waitOn: function() {
            [
             Meteor.subscribe('productMap'),
             Meteor.subscribe('products')
             ];
        }
    });
});

所以问题是,目前它仅在我打开自动发布时才找到我的 productList。如何正确发布/订阅我的:

productList = ProductMap.find({}).fetch();

当我打开新的私人会话并在我的浏览器窗口中进行刷新之前,我的插件也开启了自动发布功能。刷新后它不起作用,我需要打开新的私人窗口。使用硬定义的对象/数组,插件在任何情况下都能很好地工作。

【问题讨论】:

    标签: jquery meteor meteor-autoform meteor-publications


    【解决方案1】:

    你的问题可能是 waitOn 期望你返回数组(你忘了返回数组):

    waitOn: function() {
            return [
                 Meteor.subscribe('productMap'),
                 Meteor.subscribe('products')
                 ];
            }
    

    几乎立即从您的项目中删除自动发布包。添加的包可以正常工作,因为它会发布所有内容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-05
      • 2013-05-18
      • 2014-09-24
      • 2014-05-04
      • 1970-01-01
      • 2013-04-12
      相关资源
      最近更新 更多