我的jQuery插件发布数据存在问题。该插件是autoform添加包,其定义如下:
Products.attachSchema(new SimpleSchema({
tooteNimetus: {
type: String,
optional: true,
autoform: {
type: "selectize",
options: function () {
return productList
}
}
我需要定义这个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();
也是我的潜艇并发布: 在我/服务器中:
Meteor.publish("productMap", function () {
return ProductMap.find({});
});
lib / router中的Subs:
Router.map(function () {
this.route('insert', {
path: '/insert',
template: 'insertProduct',
waitOn: function() {
[
Meteor.subscribe('productMap'),
Meteor.subscribe('products')
];
}
});
});
所以问题是目前只有在我打开autopublish时它才会找到我的productList。如何正确发布/订阅我的:
productList = ProductMap.find({}).fetch();
当我打开新的inprivate会话并且直到我在浏览器窗口中刷新时,启用了autopublish,我的插件工作正常。刷新后它不起作用,我需要打开新的私有窗口。使用硬定义的对象/数组,插件在任何情况下都能很好地工作。
答案 0 :(得分:0)
你的问题可能是waitOn希望你返回数组(你忘了返回数组):
waitOn: function() {
return [
Meteor.subscribe('productMap'),
Meteor.subscribe('products')
];
}
几乎立即从您的项目中删除autopublish pacakge。事情与添加的包一起使用,因为它发布了所有内容。