【问题标题】:Meteor publishing field issue流星出版领域问题
【发布时间】:2015-04-02 03:52:39
【问题描述】:

我的应用程序不应该发布“memberPrice”字段。在我的 publish.js 文件中,我指定了不发布 memberPrice。这是我的服务器/publish.js:

Meteor.publish('cars', function() {
return Products.find({category: 'vehicle'}, {limit: 10}, {fields: {memberPrice: 0}});
});

我的控制器:

carsController = RouteController.extend({
waitOn: function () { 

    var sessionId = Session.get('sessionId');
    console.log("Session: ", sessionId);
    Meteor.subscribe('cars');
    Meteor.subscribe('cartItems', sessionId);

},
action: function() {
    this.render('Cars');
}

});

这是我使用 aldeed:tabular 包的表格:

TabularTables = {};

Meteor.isClient && Template.registerHelper('TabularTables', TabularTables);

TabularTables.Cars = new Tabular.Table({
name: "Cars",
collection: Products,
columns: [
{data: "productCode", title: "Product Code"},
{data: "brand", title: "Brand"},
{data: "productLineName", title: "Product Name"},
{data: "description", title: "Description"},
{data: "memberPrice", title: "Member Price"}

 ]
});

有人知道怎么回事吗?

谢谢!

【问题讨论】:

  • cartItems publish 返回的是什么?另一个系列?还是 Products collection 光标?

标签: javascript meteor publish


【解决方案1】:

您将三个参数传递给Products.find,但它只需要两个。 {limit: 10}, {fields: {memberPrice: 0}} 应该是 {limit: 10, fields: {memberPrice: 0}}

【讨论】:

    【解决方案2】:

    过去我确实像您所拥有的那样发布,但自从我从David Weldon 页面阅读这篇文章。

    我将发布更改为类似的内容。

    Meteor.publish('cars', function() {
      var selector = {category: 'vehicle'};
      var options = {limit: 10,fields: {memberPrice: false}};
      return Products.find(selector,options);
    });
    

    根据您拥有的 Publish 功能,memberPrice 选项应在此处排除,试试这个,这里我们遵循 Collection.find 的正确语法,即 collection.find([selector], [options]) 并且您有类似 collection.find([selector],[selector],[options]) 的内容。

    【讨论】:

    • 哈哈,其实是“Weldon”。另外,也许您应该对该文章的重要内容添加一点精确度。
    • @Kyll haha​​ 我想我要删除这个,因为我看不到 Peep 答案是一样的,我只是在这里更改发布语法。
    • 该死的我不知道你是怎么接受的,Peppe L-G 的回答更有意义!编辑 - 哦,等等,现在我已经阅读了你的编辑。好电话。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-13
    • 1970-01-01
    • 1970-01-01
    • 2013-04-12
    • 1970-01-01
    • 2017-10-15
    • 1970-01-01
    相关资源
    最近更新 更多