【问题标题】:Meteor-aldded:tabular collection undefined errorMeteor-aldded:表格集合未定义错误
【发布时间】:2015-03-08 16:13:17
【问题描述】:

我有下表可以正常工作。作为一个管理员帐户,我发布了整个 Meteor.users 集合。我在根 /lib 的一个文件中也有两个数据库

Clients = new Meteor.Collection("client");
Brands = new Meteor.Collection("brand");

它们现在像这样在 /server/lib 文件夹中发布

Meteor.publish("pubClients", function(){
  return Clients.find();
});
Meteor.publish("pubBrands", function(){
  return Brands.find();
});
Meteor.publish("pubUsers", function(){
  return Meteor.users.find();
});

并在 client/lib 文件夹中这样订阅

Meteor.subscribe('pubClients');
Meteor.subscribe('pubBrands');
Meteor.subscribe('pubUsers');

我正在使用以下模板来注入 html: {{> tabular table=TabularTables.Users selector=selector class="table table-striped table-bordered table-condensed"}}

现在,如果我尝试将 Meteor.user 更改为任何 Clients 或 Brands 集合,甚至在此代码上方插入 console.log(Clients),我会收到:“Clients is not defined”错误。 如果我在运行重新运行应用程序之前输入控制台 > 客户端,它可以与 Mongo.Collection 等一起正常工作。 如果我运行它,我也会在控制台中收到未定义的消息。 这是我的代码(实际上是 aldeed 的代码 :)):

TabularTables = {};

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

TabularTables.Users = new Tabular.Table({
name: "UserList",
collection: Meteor.users,
pub:"pubUsers"
columns: [
{data: "username", title: "User name"},
{
  data: "emails",
  title: "Email",
  render: function (val, type, doc) {
    return val[0].main
  }
},
{
  data: "emails",
  title: "verified",
  render: function (val, type, doc) {
    return val[0].verified?"☑":"☐";
  }
},
{
data: "profile",
title: "Account",
render: function (val, type, doc) {
return val.accType;
}
},
{
  data: "profile",
  title: "Active",
  render: function (val, type, doc) {
    return val.active?"active":"pending";
  }
},
{
  data: "createdAt",
  title: "Singned up",
  render: function (val, type, doc) {
    return moment(val).calendar();
  }
},
  {
    tmpl: Meteor.isClient && Template.bookCheckOutCell
  }
]
});

有什么想法吗?

非常感谢。这是我的包裹清单:

accounts-base      1.1.3  A user account system

accounts-password  1.0.5  Password support for accounts

aldeed:tabular     0.2.3  Datatables for large or small datasets in Meteor

insecure           1.0.2  Allow all database writes by default

iron:router        1.0.6  Routing specifically designed for Meteor

meteor-platform    1.2.1  Include a standard set of Meteor packages in your app

momentjs:moment    2.9.0  Moment.js (official): parse, validate, manipulate, and display dates - official Meteor packaging

sergeyt:typeahead  0.10.5_7  Autocomplete package for meteor powered by twitter typeahead.js

twbs:bootstrap     3.3.1_2  Bootstrap (official): the most popular HTML/CSS/JS framework for responsive, mobile first projects

我在应用程序的其他地方使用这个集合,它工作正常。由于我安装了表格包 事情不知何故失控了。我不知道要从哪里开始。 我现在苦苦挣扎了两天才能让它工作,但是网上关于这个包(以及大多数 Meteor 相关主题)的信息太少了,所以我决定发布这个问题。

【问题讨论】:

    标签: meteor tabular


    【解决方案1】:

    我不确定,看起来像加载顺序问题

    尝试在同一个文件中初始化集合后编写表格代码

    在根目录/lib 文件夹中

    Clients = new Meteor.Collection("client");
    Brands = new Meteor.Collection("brand");
    
    
    Meteor.isClient && Template.registerHelper('TabularTables', TabularTables);
    
        TabularTables.Users = new Tabular.Table({
        name: "UserList",
        collection: Meteor.users, //Clientsor Brands
        pub:"pubUsers"
        columns: [
        {data: "username", title: "User name"},
        {
          data: "emails",
          title: "Email",
          render: function (val, type, doc) {
            return val[0].main
          }
        },
    

    【讨论】:

    • 你成就了我的一天!!!!如果除了投票之外还有一个“拥抱”按钮,我也会按下它。我现在意识到加载顺序至关重要。您能否向我推荐一个文档或其他东西来了解我如何控制它。一个 package.js 可能吗? ()我对流星很陌生,我还没有“感觉到”这个框架。再次感谢一千次!
    • @vladblindu,要了解文件加载顺序,请访问此链接meteorsnippets.com/blog/files-load-order-in-meteor
    猜你喜欢
    • 1970-01-01
    • 2014-01-01
    • 2013-07-10
    • 1970-01-01
    • 2013-07-30
    • 2015-05-05
    • 1970-01-01
    • 2014-08-15
    • 2014-12-01
    相关资源
    最近更新 更多