【发布时间】: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